Applesoft BASIC Programmers Reference Manual
Applesoft BASIC Programmers Reference Manual
•
•
•
•
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system,
or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or
otherwise, without prior written permission of Apple Computer, Inc. Printed in the United States
of America.
Scot Kamins
Technology Translated, Inc.
San francisco, California
Apple, the Apple logo, and ProDOS are registered trademarks of Apple Computer, Inc.
ISBN 0-201-17756-0
ABCDEFGHIJ-DO-8987
First printing, July 1987
WARRANTY INFORMATION
ALL IMPLIED WARRANTIES ON THIS MANUAL, INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE, ARE LIMITED IN DURATION 'IO NINETY (90) DAYS FROM THE DATE OF THE ORIGINAL RETAIL
PURCHASE OF THIS PRODUCT.
Even though Apple has reviewed this manual, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER
EXPRESS OR IMPLIED, WITH RESPECT 'IO THIS MANUAL, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR fflNESS FOR A
PARTICULAR PURPOSE. As A RESULT, THIS MANUAL IS SOLD "AS IS;' AND YOU, THE PURCHASER, ARE ASSUMING THE
ENTIRE RISK AS 'IO ITS QUALITY AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
RESULTING FROM ANY DEFECT OR INACCURACY IN THIS MANUAL, even if advised of the possibility of such
damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL <JI'HERS, ORAL OR WRIITEN,
EXPRESS OR IMPLIED. No Apple dealer, agent or employee is authorized to make any modification,
extension, or addition to this warranty.
Some states do not allow the exclusion or limitation of implied warranties or liability for in
cidental or consequential damages, so the above limitation or exclusion may not apply to you.
This warranty gives you specific legal rights, and you may also have other rights which vary
from state to state.
Applesoft BASIC
Programmer's Reference Manual
Contents
iv Contents
1.2 Operations on Whole Programs 7
1.2.1 The NEW Command 7
1.2.2 The CLEAR Command 8
1.2.3 The LIST Command 9
1.2.4 The RUN Command 10
1.2.5 The SAVE Command 11
1.2.6 The WAD Command 12
1.3 Interrupting and Resuming a Program 13
1.3.1 Suspending Screen Output 13
1.3.2 Interrupting Program Execution 14
1.3.2.1 CONTROL-C 14
1.3.2.2 CONTROL-RESET 14
1.3.3 Resuming Program Execution: The CONT Command 15
1.4 Editing What You Type 16
1.4.1 Canceling an Input Line 16
1.4.2 The Arrow Keys 17
1.4.3 Escape Mode 18
Contents V
2.3 Expressions 28
2.3.1 Arithmetic Operators 29
2.3.2 Relational Operators 30
2.3.3 Logical Operators 32
2.3.4 Precedence of Operators 33
2.4 Functions 35
2.4.1 Built-in Arithmetic Functions 35
2.4.1.1 The ABS Function 36
2.4.1.2 The SGN Function 36
2.4.1.3 The INT Function 36
2.4.1.4 The SQR Function 37
2.4.1.5 The SIN Function 37
2.4.1.6 The COS Function 37
2.4.1.7 The TAN Function 38
2.4.1.8 The ATN Function 38
2.4.1.9 The EXP Function 38
2.4.1.10 The LOG Function 39
2.4.2 Generating Random Numbers: The RND Function 39
2.4.3 Defining Your Own Functions: The DEF FN Statement 40
vi Contents
3.3 Loops 50
3.3.1 The FOR Statement 52
3.3.2 The NEXT Statement 53
3.3.3 Nesting of Loops 54
3.4 Subroutines 55
3.4.1 The GOSUB Statement 59
3.4.2 The RETURN Statement 59
3.4.3 The ON...GOSUB Statement 59
3.4.4 The POP Statement 60
3.5 Error Handling 61
3.5.1 The ONERR...GOTO Statement 61
3.5.2 The RESUME Statement 65
3.5.3 Restoring Normal Error Handling 65
3.6 Program Termination 57
3.6.1 The STOP Statement 67
3.6.2 The END Statement 67
Contents vii
4.2 Strings 74
4.2.1 Comparison of Strings: The ASCII Code 75
4.2.2 The LEN Function 76
4.2.3 Concatenation of Strings 77
4.2.4 Substring Functions 79
4.2.4.1 The LEFT$ Function 79
4.2.4.2 The MID$ Function 80
4.2.4.3 The RIGHT$ Function 81
4.2.5 String Conversion Functions 81
4.2.5.1 The STR$ Function 82
4.2.5.2 The VAL Function 82
4.2.5.3 The CHR$ Function 83
4.2.5.4 The A$C Function 84
CHAPTER5 Input/Output 85
5.1 Input 86
5.1.1 The IN# Statement 86
5.1.2 The INPUT Statement 88
5.1.2.1 Multiple Inputs on the Same Line 89
5.1.2.2 General Rules for Input 90
5.1.2.3 Rules for String Input 90
5.1.2.4 Rules for Numeric Input 91
5.1.2.5 An "Input Anything" Routine 93
5.1.3 The GET Statement 94
5.1.4 The READ and DATA Statements 96
5.1.5 The RESTORE Statement 98
viii Contents
5.1.6 Miscellaneous Input Facilities 99
5.1.6.1 The Hand Controls 99
5.1.6.2 Cassette Input 100
5.2 Output 101
5.2.1 The PR# Statement 101
5.2.2 The PRINT Statement 102
5.2.3 Number Formats 106
5.2.4 Formatting Text on the Screen 108
5.2.4.1 The Text Window 109
5.2.4.2 The TEXT Statement 109
5.2.4.3 The HOME Statement 109
5.2.4.4 The SPC Function 109
5.2.4.5 The TAB Function 111
5.2.4.6 The HTAB Statement 112
5.2.4.7 The VTAB Statement 113
5.2.4.8 The POS Function 114
5.2.4.9 The INVERSE Statement 115
5.2.4.10 The FLASH Statement 115
5.2.4.11 The NORMAL Statement 116
5.2.4.12 The SPEED= Statement 117
5.2.5 Miscellaneous Output Facilities 118
5.2.5.1 Controlling the Speaker 118
5.2.5.2 Annunciator Output 119
5.2.5.3 The Utility Strobe 119
5.2.5.4 Cassette Output 119
Contents ix
CHAPTER6 Graphics 121
6.1 Low-Resolution Graphics 122
6.1.1 The GR Statement 122
6.1.2 The COLOR= Statement 123
6.1.3 The PLOT Statement 125
6.1.4 The HLIN Statement 127
6.1.5 The VLIN Statement 128
6.1.6 The SCRN Function 129
6.2 High-Resolution Graphics 130
6.2.1 The HGR Statement 130
6.2.2 The HGR2 Statement 131
6.2.3 The HCOLOR= Statement 133
6.2.4 The HPLOT Statement 134
6.2.5 Protecting High-Resolution Graphics 137
6.3 Shape Tables 138
6.3.1 Creating a Shape Table 138
6.3.1.1 Plotting Vectors 139
6.3.1.2 How Plotting Vectors Are Interpreted 140
6.3.1.3 Coding a Shape Table 140
6.3.1.4 The Shape Table Index 144
6.3.1.5 Loading a Shape Table Into Memory 146
6.3.1.6 Saving and Loading a Shape Table 149
X Contents
6.3.2 Using Shape Tables 151
6.3.2.1 The DRAW Statement 152
6.3.2.2 The XDRAW Statement 153
6.3.2.3 The SCALE= Statement 154
6.3.2.4 The ROT= Statement 155
6.3.2.5 The SHLOAD Statement 156
6.4 Graphics in Text Mode (MouseText) 158
Contents xi
CHAPTERS Programming: Bringing It All Together 175
8.1 Planning the Program 176
8.1.1 Program Specification 176
8.1.1.1 What the Program Needs 176
8.1.1.2 What the Program Will and Won't Do 177
8.1.1.3 Validating the Data 178
8.1.1.4 Displaying the Results 179
8.1.1.5 Final Specifications 179
8.1.2 Program Layout 180
8.1.2.1 The Initial Layout 180
8.1.2.2 Refining the Layout 181
8.2 Writing the Code 183
8.2.1 Preliminaries 184
8.2.2 Display the Menu 184
8.2.3 What's the Postage Class? 185
8.2.4 What Does It Weigh? 186
8.2.5 Compute the Charge 187
8.2.6 Display the Results 188
8.2.7 Calculating Routines 188
8.2.8 Consistency-Checking Routines 190
8.2.9 The Keystall Routine 192
8.2.10 The Formatting Routine 193
8.3 Final Advice to the New Programmer 193
xii Contents
APPENDIXA Summary of Applesoft Statements and Functions 195
Contents xiii
F.4 Miscellaneous Input and Output 254
F.4.1 Hand Controls and Strobe 254
F.4.2 Annunciators 255
F.4.3 Loudspeaker 256
F.5 Error Handling 257
xiv Contents
APPENDIXL Comparison With Integer BASIC 287
L.1 Differences Between Statements 289
L.2 Other Differences 290
L.3 Converting BASIC Programs to Applesoft 291
Contents xv
Glossary 317
Index 331
Applesoft BASIC Quick Reference Card
Tell Apple Card
xvi Contents
Figures and Tables
As a Reference Book
There are several ways you can use this book as a reference:
□ Look up the feature of interest on the quick reference card; each
statement, function, operator, and variable type is listed there in an
extremely abbreviated form as a memory aid.
□ Look up the feature in Appendix A, "Summary of Applesoft Statements
and Functions." Each statement and function is described briefly, and a
reference is given to the chapter, section, or appendix where it is
discussed in detail:
□ Look up the feature in the index. There you'll find page numbers of the
places in the manual where it is mentioned.
□ Look in the appendixes at the back of the manual for quick reference on
specific facts.
If you already know something about Applesoft and want to increase your
programming skill and efficiency:
□ Read through Chapter 8 and experiment with the program developed
there.
□ Develop your own programs based on the methods presented in
Chapter 8.
□ Restructure someone else's program using the methods in Chapter 8.
□ Read Appendix G, "Hints for Program Efficiency," at the back of the
manual.
•
•
..,, .,·
... •' . •
•
•
•
•
BASIC: Beginner's All-purpose Symbolic Applesoft BASIC is a very extended version (in computer parlance, a
Instruction Code superset) of the BASIC programming language. It includes many more
features than either the original BASIC, developed at Dartmouth College in
the 1960s, or the standard version of the language, as defined by the
American National Standards Institute (ANSI). The extra features allow
your programs to use the special capabilities of the Apple II, such as color
graphics, animation, and hand controls.
This first chapter introduces the Applesoft language and the environment
in which it operates. Here you will find information on how to create,
modify, execute, and store Applesoft programs.
o Section 1.1, "Statements, Lines, and Programs," deals with the
fundamental units of Applesoft programs. It tells how to type Applesoft
statements for immediate execution and how to create and modify
programs in the computer's memory.
o Section 1.2, "Operations on Whole Programs," introduces Applesoft's
commands for displaying a program on the screen, writing it to an output
device such as a printer, executing it, saving it on a disk, and retrieving it
from a disk.
o Section 1.3, "Interrupting and Resuming a Program," tells how to suspend
or cancel the execution of a running program and how to resume
execution after an interruption.
o Section 1.4, "Editing What You Type," briefly describes Applesoft's
facilities for correcting typing errors and editing text on the screen.
1 . 1 . 1 Immediate Execution
To add a new line to a program, just type the new line preceded by a line
number indicating where in the program you wish to insert it. It makes no
difference in what order you enter program lines; Applesoft puts them in
the proper order for you.
Helpful Hint: Instead of using consecutive line numbers (0, 1, 2...), it's
usually more convenient to leave intervals of 5 or 10 or 20 between the
line numbers in your program. This makes it easy to insert new lines, if
necessary, in between the old ones.
The DEL command deletes (removes) a range of consecutive lines from the
program currently in memory. The line numbers of the first and last lines to
be deleted follow the keyword DEL and are separated from each other by a
comma. All program lines between and including the two specified line
numbers are deleted from the program. This example, for instance, deletes
lines 100 to 200, inclusive.
If either line number is out of the range of lines in the actual program (for
instance, if the command is DEL 100, 200 and the highest existing line
number is 150), then all existing lines within the specified range are
deleted. If DEL specifies a range of lines that doesn't exist, or if the second
line number is smaller than the first, the command has no effect:
DEL 2 0 0 , 1 0 0 Nothing happens.
A single number with a comma also has no effect:
DEL 35 ,
To replace an existing line of your program, simply type the new line using
the same line number as the existing one. What you type replaces the old
line under the same line number; the old line is forgotten.
To alter an existing line, either retype the line or use your computer's
editing facilities, discussed in Section 1.4 and in Appendix J.
MEW
The NEW command clears the current program from memory, resets the
values of all numeric variables to O and those of all string variables to the
null string, and prepares Applesoft to accept a new program. If there are no
programs and no variables in memory, NEW has no effect.
When you sit down to start typing a new program, always begin by typing
NEW. Otherwise, you might find that you're not typing a new program at
all, but just editing the first lines of a program already in memory.
Although NEW is usually used in immediate execution, you can also use it
in deferred execution (from within a program):
1 00 I F A $ • "RATS" THEM MEW
NEW in conditional statement.
999 MEW NEW on its own line.
CLEAR
The CLEAR command resets the values of all numeric variables to O and
null string: a string containing no those of all string variables to the null string; it also resets Applesoft's
characters internal control information to its initial state. It has no effect on the
contents of the program lines in memory.
Although CLEAR is usually used in immediate execution, you can also use it
in deferred execution (from within a program):
1 00 I F 2 $ • " N UT S " T H E N C L E A R
CLEAR in conditional statement.
999 CLEAR CLEAR on its own line.
.A.Warning Be careful where you execute CLEAR. Since CLEAR resets Applesoft's
internal control stack, using it in the midst of a subroutine or in a
subroutines, control stack: see FOR/NEXT loop can interfere with the orderly flow of program
Section 3.4 execution. The following program, for example, crashes in line 40 with a
N E X T W I T H O U T F O R error:
10 FOR X 1 TO 1 0 Tries to loop 10 times.
20 PR I NT X
30 CLEAR CLEAR resets control stack
( among other things).
40 NEXT X Program fails here-doesn't know
it's in a loop.
50 PR I NT "H I ! " Program won't get this far.
L I ST 1 0 0 , 2 0 0
L I ST 1 0 0 - 2 0 0
The LIST command displays on the screen all or part of the program
currently in memory, or writes it to the current output device as specified in
the last PR# statement. (See Section 5.2.1.) For example, if there is a
printer connected to slot 1 or port 1, and if the statement P R # 1 has been
executed, then the program listing is sent to the printer.
To list the entire program, just type
L I ST
RUN
RUN 275
R U N M O N TH L Y . BUDGET
The RUN command instructs Applesoft to execute the program currently in
memory. If no line number is given, execution begins at the beginning of the
program; if the RUN command includes a line number, execution begins at
the specified line:
RUN Executes program from beginning.
RUN 5 0 0 Executes program from line 500.
If you attempt to run a program from a specified line number (as in
R U N 5 0 0) and that line doesn't exist, the message ? U N D E F ' D
S T A T E M E N T E R R O R is displayed and program execution halts.
Although RUN is normally used in immediate execution, you can also use it
from within a program:
1 5 0 I F A • 0 THEN RUN If value of A is 0, then executes
program from beginning.
235 RUN 6 0 0 Executes program from line 600.
You can use this technique, for example, to restart a game or to avoid
executing some code with low line numbers.
1 .3.2. 1 CONTROL-C
Pressing � (pressing @] while holding down I CONTROL D
cancels the execution or listing of a program and returns Applesoft to its
command level, displaying the prompt character ( ] ). You can then resume
execution of the program, if you wish, with the CONT command.
Canceling a Program Waiting for a Response: To cancel a program
that is waiting for a response to an INPUT statement (see Section 5.1.2),
press � and follow it immediately with I RETURN 1.
� does not interrupt a program waiting for a response to a
GET statement (see Section 5.1.3). Unlike the INPUT statement, GET
assumes that � is a valid response and assigns the ASCII
code for the character � to the specified variable. To allow a
program halted at a GET statement to be interrupted with �.
use this form in the program:
2s0 GET A $ Waits for user to press a key
260 I F A $ • C H R $ C 3 ) T H E N STOP
If user presses �
(ASCII code 3), then stops
_..warning In certain situations, using � can disconnect the disk
operating system. See the disk operating system manual for information
on this point.
1 .3.2.2 CONTROL-RESET
In most cases you can immediately and unconditionally stop the execution
of any Applesoft program or command by pressing I CONTROL H RESET I
(pressing I RESET !While holding down I CONTROL I). The program in memory
remains intact, but some of Applesoft's internal "housekeeping" information
is changed; as a result, it may not be possible to resume execution of the
program with the CONT command.
CONT
The CONT (for continue) command is used to resume execution of a
program after it has been interrupted by a STOP (see Section 3.6.1) or END
statement (see Section 3.6.2) or by pressing �- Execution
resumes at the first statement after the STOP or END, or at the point in the
program where execution was interrupted by � (see
Section 1.3.2).
CONT won't work if
□ the program has been stopped because of an error
□ an error has occurred in immediate execution
□ an INPUT statement has been interrupted with �
□ the CLEAR or NEW command has been executed
□ any program line has been edited since the program stopped running
□ there are no more program lines after STOP or END.
However, you can continue the program with CONT after examining or
changing the values of variables, provided you haven't edited any program
lines.
Important! Resuming after I CONTROL H RESET J: When a program is interrupted with
I CONTROL H RES ET I, CONT may or may not continue execution. Let the
programmer beware!
.A.Warning I The CONT command should be used in immediate execution only. If it is
executed from within a program, it causes the program to hang.
There are four arrow keys on most models of the Apple II keyboard:
□ The G key works as a backspace. It moves the cursor one position to the
left and causes Applesoft to forget the last character typed from the
keyboard (or recopied with the G key;), though no characters are
removed from the screen. If any pure cursor moves (see Section 1.4.3)
have been used, the character "erased" may not be the one the cursor
backs up over.
□ The G key recopies the character under the cursor as if it had been
typed from the keyboard, then moves the cursor one position to the right.
Moving the cursor over a character with G is exactly the same as typing
that character from the keyboard.
□ The [I) key moves the cursor down one line without erasing or recopying
any characters. Neither the Apple II nor the Apple II Plus has this key.
□ The [I) key has no effect in Applesoft.
In escape mode (see Section 1.4.3), all four arrow keys lose their backspace
and recopy functions and simply move the cursor one position in the
indicated direction.
Fast Moves: The Apple II keyboard's auto-repeat feature is particularly
handy for long cursor moves. If you press and hold down any of the arrow
keys, the cursor moves repeatedly in the indicated direction for as long as
you hold down the key. (Exception: the [I) key doesn't move the cursor
unless you're in escape mode.)
Every time you press an arrow key, you send an ASCII code (see
Section 4.2.1 and Appendix C) to the computer. Table 1.1 shows which
codes correspond to which keys.
G 8 �
G 21 I CONTROL !{ill
m 11
10
�
I CONTROL ID]
[I)
If you press I ESC I while the 1 prompt is on the screen, you put Applesoft
into escape mode, in which certain keys take on special meanings. Some
of the keys become pure cursor moves, meaning that they move the cursor
around on the screen without erasing or recopying characters or affecting
Applesoft's input in any way. Others can be used to clear away text from all
or part of the screen, again without having any effect on the input received
by Applesoft.
Letters Can Be Uppercase or Lowercase: All of the letter keys listed
have the same effect whether they are typed in uppercase or lowercase
on all Apple II series computers.
In escape mode, the following characters move the cursor one position in
the stated direction and then leave escape mode. To continue moving the
cursor, you have to press I Esc I again. The functions of these keys are
Figure 1-1. Single Cursor Moves illustrated in Figure 1-1.
□ IA] moves the cursor one position to the right.
□ []] moves the cursor one position to the left.
□ @] moves the cursor down one line.
□ [[) moves the cursor up one line.
Key Function
21
This chapter deals with variables and arithmetic in Applesoft. These
concepts are fundamental to Applesoft programming and appear again and
again throughout this manual.
□ Section 2.1, "Variables," discusses how to define and use variables, the
various types of variables available in Applesoft, and the rules for
naming them.
□ Section 2.2, "Assigning Values: The Assignment Statement," deals briefly
with one of Applesoft's most basic types of statements, the assignment
statement.
□ Section 2.3, "Expressions," discusses arithmetic operators and
expressions and the rules of precedence that govern them.
□ Section 2.4, "Functions," covers Applesoft's built-in arithmetic functions
and tells how you can define your own functions.
2.1 Variables
2. 1 . 1 Variable Names
The name of a variable must begin with a letter of the alphabet, which may
be followed by one or more letters and/or digits. In addition, the names of
all integer variables must end with a percent character (%) and those of
string variables must end with a dollar sign ($). The various variable types
and the rules for naming them are summarized in Table 2-1.
Simple Array
Type Suffix Examples Examples
Real (none) K AGE (CHILD)
PRICE TAX (ITEM)
Nl Nl (J %,3)
Integer % J% YEAR% (N)
G5% BOOK% (COUNT)
N1% Nl% (J%,3)
String $ A$ SHOP$ (5)
SAM$ DAY$ (WEEK)
N1$ Nl$ (J%,3)
A variable name can be up to 238 characters long, but Applesoft uses only
the first two characters to distinguish one variable from another of the same
type. Except for the suffix, all characters beyond the first two in a name are
ignored, as long as they don't include a reserved word.
2.1 Variables 23
.A.Warning Take care not to begin the names of different variables of the same type
with the same two characters. Applesoft considers the names SUM and
SUNSTROKE, for example, to refer to the same variable, since they both
begin with the same two characters.
Notice that this restriction applies only to variables of the same type.
Applesoft considers the names TAX, TAX%, and TAX$ to refer to three
different variables, even though they all begin with the same two
characters, because they are of different types (real, integer, and string).
Reserved Words: Certain words used in Applesoft are reserved for
special uses in specific commands; you can't use these words as variable
names or as parts of variable names (even beyond the first two
characters). For instance, TOTAL or SUBTOTAL are illegal as variable
names, because they both contain the reserved word TO. See Appendix D
for a list of Applesoft's reserved words.
2.1 Variables 25
A string can contain from O to 255 characters; when it contains no
characters it is called a null string. Two quotation marks with nothing
between them denote the null string:
11 11
A string variable can hold any string as its value. Its name must end with a
dollar sign ($). Some legal string variable names are
NAME$
S9$
J$
Until they are given some other value with an assignment statement, all
string variables are preset to the null string.
2.3 Expressions
3 + 4 3 plus 4, yielding 7.
+ 1 44 Plus 144 (a positive number).
x + v The value of X plus the value of Y.
23 . 7 - 1 1 . 4 23.7 minus 1.4, yielding 12.3.
5e - 75 50 minus 75, yielding -25.
- 1 44 Minus 144 (a negative number).
SUMX - 2 The value of SUM% minus 2.
13 * 5 13 times 5, yielding 65.
6 * . 25 6 times .25, yielding 1.5.
25 * Q U A R T E R S X 2 5 times the value of QUARTERS%.
4 . 0 * co u tH c 5 > 4.8 times the value of element 5 of
array COUNT.
10 1 s 18 divided by 6, yielding 3.
s 1 10 6 divided by 18, yielding .333333333.
D I sr I T I M E The value of DIST divided by the
value of TIME.
D□ L L A R S X 1 1 0 0 The value of DOLLARS% divided
by 100.
2 " 3 2 to the 3rd power, yielding 8.
3 ,. . 5 3 to the .5 power,
yielding 1.73205081.
x " JX The value of X raised to the power
of the value of J%.
Note: Like most other computer languages, Applesoft uses an asterisk
( * ) instead of the letter x to represent multiplication.
2.3 Expressions 29
What to Do With Fractions: Applesoft doesn't treat fractional numbers
in the way that you are probably used to dealing with them. Most people
would read the expression 3 3/4 as three and three quarters. To
Applesoft, however, the same expression would mean thirty-three
divided by four. (Applesoft ignores any spaces it finds in a number.)
It's easy to convert fractions to a form Applesoft understands correctly.
Just think of 3 3/4 as three plus three divided by four. In other words,
instead of typing
LET A • 3 3 / 4
type this:
LET A • 3 + 3/4
Applesoft does the rest.
2 . 3 Expressions 31
6 >· 6 6 is greater than or equal to 6,
6 ·> 6 yielding 1 for true.
6 >• 12 6 is greater than or equal to 12,
6 •> 12 yielding O for false.
S A L A R Y > · 2 fil fil fil fil The value of SALARY is greater
S A L A R Y • > 2 fil fil fil fil than or equal to 20000.
6 <> 6 6 is not equal to 6, yielding O for
6 >< 6 false.
6 <> 12 6 is not equal to 12, yielding 1 for
6 >< 12 true.
X <> y The value of X is not equal to the
X >< y value of Y.
B A N G $ > < "WH I MP E R " The value of BANG$ is not equal to
B A N G $ < > "WH I MP E R " the string "WHIMPER."
2.3 Expressions 33
Notice that the operators + and - have higher precedence when used to
represent the sign of a number ( as in + 144 or -X) than when they stand for
the operations of addition and subtraction.
To understand how Applesoft's precedence rules work, consider the
expression
-2 * 2 A 3 + Q / 5 - A * B
When Applesoft evaluates this expression, it begins by applying the first
minus sign to the constant 2, obtaining a result of -2. Next it raises the value
of Z to the 3rd power and multiplies the result by -2. Then it divides the
value of Q by 5 and adds the result to that of the previous calculation.
Finally, it multiplies the values of A and B and subtracts that result from
the previous one.
For example, suppose the current values of the variables in this expression
are as follows: Z = 2, Q = 10, A = 7, B = 4. Then
-2 = -2
z 3
A =8
-2 * 8 = -16
Q/5 = 10 / 5 =2
-16 + 2 = -14
A*B = 7*4 = 28
-14 - 28 = -42
The value of the expression is -42.
Parentheses can be used to change the normal order of precedence. For
example:
-2 * 2 A C3 + Q) / 5 - A * B
Value is -3304.8; (3 + Q) evaluated
as a unit.
-2 * 2 A 3 + CQ / 5 - A) * B
Value is -36; ( Q / 5 - A) evaluated as
a unit.
-2 * 2 A 3 + Q / c s - A * B>
Value is -16.4347826;
(Q / (5 - A * B)) evaluated as a unit.
The original expression above is equivalent to the fully parenthesized
expression
C C C -2) * CZ A 3)) + CQ / 5 ) ) - C A * B>
2.4 Functions
A function is a preprogrammed calculation that can be carried out on
request. You can use functions whenever you need to perform the same
calculation repeatedly throughout a program. Whenever you call a function
(request its execution), you must give it a particular value to operate on;
this value is called the argument of the function.
Applesoft offers a variety of built-in functions, discussed in Section 2.4.1,
for calculating common mathematical values such as logarithms, cosines,
and square roots. Section 2.4.2 covers the built-in function RND, used for
generating random numbers. In addition, you can define your own functions
for the special needs of a particular program-see Section 2.4.3 for details.
This section discusses the various built-in functions that Applesoft provides
for calculating commonly used mathematical quantities. To call a built-in
function, just type the name of the function followed by an expression in
parentheses representing the argument value on which you want the
function to operate. For example, suppose you need to calculate the square
root of a number. Applesoft has a built-in function named SQR for this
purpose; to find the square root of 3, type
SQR C 3 )
To find the square root of the value of variable X plus 2 , type
SQR C X + 2 )
2.4 Functions 35
2.4. 1 . 1 The ABS Function
The built-in function ABS computes the absolute value of a number-that
is, the positive numerical value of the number, without regard to its original
sign. For example,
ABS ( 2 7 ) Absolute value of 27; yields 27.
ABS C - 2 7 ) Absolute value of -27; yields 27.
A B S c 36 . a 23 . 3 ) Absolute value of 36.8 minus 23.3i
yields 13.5.
A B S ( 2 3 . 3 - 36 . 8 ) Absolute value of 23.3 minus 36.8;
yields 13.5.
ABS C C X C 9 » Absolute value of element 9 of
array C%.
2.4 Functions 37
2.4. 1 . 7 The TAN Function
TAN computes the trigonometric tangent of its argument. The argument
must be expressed in radians (not degrees). For example, assuming the
value of the variable PI is 3. 14159265,
TAN C P I / 3 ) Tangent of PI / 3 radians;
yields 1. 7320508.
TAN ( 1 ) Tangent of 1 radian;
yields 1.55740772.
TAN C X "2 - Y " 2 > Tangent of X squared minus Y
squared.
2.4 Functions 39
Calling RND with a negative argument causes it to begin a new, repeatable
sequence of random numbers. This is called seeding the random number
generator; the particular negative value you use for the argument acts as a
seed for the new sequence. Different seeds produce different sequences;
but each time you use the same seed you get the same result. Subsequent
calls to RND with positive arguments then produce the same sequence of
results:
RND (-1) Yields 2.99196472E-08.
RND (1) Yields .738207502.
RND (1) Yields .272707136.
RND (1) Yields .299733446.
RND ( -5) Yields 3.73720468E-08; starts new
sequence.
RND ( 1 ) Yields .407457285.
RND ( 1 ) Yields .463740324.
RND ( 1 ) Yields .387195686.
RND ( - 1 ) Yields 2.99196472E-08; repeats same
sequence as before.
RND ( 1 ) Yields .738207502.
RND ( 1 ) Yields .272707136.
RND ( 1 ) Yields .299733446.
Scientific Notation: The suffix E-08 in some of the random values
listed above means times 10 to the minus-8th power, and is an
example of the scientific notation that Applesoft uses to display certain
numbers. See Section 5.2.3 for further details.
D E F FN C U B E C X > = X * X * X
In addition to the built-in functions discussed in Sections 2.4.1 and 2.4.2,
Applesoft gives you the ability to define your own functions for the special
needs of a particular program. Defining your own functions can be a real
time-saver: instead of writing out the same complex formula over and over
again, you can simply define it once as a function, give it a name, and then
refer to it by that name whenever you need it.
To define a function of your own, use the DEF FN statement. This
statement consists of the keywords DEF FN (for define function) followed
argument: the value on which a function by the name of the function you're defining, the argument name enclosed in
operates parentheses, an equal sign ( = ), and the formula defining the function.
2.4 Functions 41
The DEF FN statement can be executed only from within a program; you
can't use this statement in immediate execution.
To call a function that you've defined with DEF FN, type the keyword FN
(for function) followed by the name of the function and an expression in
parentheses representing the argument value on which you want the
function to operate. For example, using the functions you defined,
F H F T C c s0 . G > Converts 98.6 degrees Fahrenheit to
Celsius; yields 37.
F ti C T F c 1 0 e > Converts 100 degrees Celsius to
Fahrenheit; yields 212.
F ti D T R c 1 0 e > Converts 180 degrees to radians;
yields 3.14159265.
F ti RTD c P 1 1 2 > Converts PI / 2 radians to degrees;
yields 90.
Note that the keyword FN is used in calling your own defined functions, but
not for built-in functions. (See Section 2.4.1.)
..
43
Ordinarily, Applesoft program lines are executed sequentially, from the
lowest-numbered line to the highest. Control statements allow you to
branch to another part of the program: that is, to alter the order of execution
and send control to a line of the program other than the next line in
sequence. This ability to change the course of program flow is what gives
computer programs their real power and flexibility.
□ Section 3.1, "Unconditional Branching: The GOTO Statement," deals
with the GOTO statement, which sends control unconditionally to a
specified line of the program.
□ Section 3.2, "Conditional Branching," discusses conditional branching
statements, which allow the program to decide what to do next by
evaluating an expression or testing for a condition.
□ Section 3.3, "Loops," covers statements that are used in loops (portions of
a program that are executed many times repeatedly).
□ Section 3.4, "Subroutines," deals with the very important subject of
subroutines: sections of a program that can be executed on request from
elsewhere in the program to perform some particular task.
□ Section 3.5, "Error Handling," describes Applesoft's facilities for
detecting and dealing with error conditions that arise during the
execution of a program.
□ Section 3.6, "Program Termination," covers the various ways of ending
program execution.
When this program is run, the IF test in line 40 fails, the values of J and K
are not changed, and execution continues with line 50. If line 20 were
changed to
2 1! LET A • 25
then the IF test in line 40 would succeed, the values of J and K would be
changed, and control would branch to line 100.
variable X.
5 0 P R I NT Displays blank line (for neatness).
60 NEXT X Repeats loop for next value of X.
7 0 P R I NT " L O O P F I N I S H E D " Control comes here after last pass
through loop.
80 END
The loop begins with the FOR statement in line 10, which specifies that the
loop is to be executed once for each value of index variable X from 3 to 10.
Lines 20 to 50 form the body of the loop. The NEXT statement in line 60
marks the end of the loop and sends control back to line 20 for the next
value of X. After the loop is executed for the last time, with X set to the
specified ending value of 10, X is increased to 11. Since this exceeds the
ending value, control falls through the NEXT statement to line 70.
3.3 Loops 51
3.3. 1 The FOR Statement
FOR V • 1 TO 1 0
FOR MASS • 3 . 5 TO 7 STEP 1 . 5
FDR V E A R • 1 98 0 TD 1 96 0 S T E P - 4
FDR V • A + 2 T D 2 * B - 3 STEP C / 2
The FOR statement marks the beginning of a loop, identifies the loop's
index variable, and gives the starting and ending values of the index
variable. It may also optionally specify the step value, the amount by
which the value of the index variable is to change on each pass through the
loop. If no step value is given, a value of 1 is understood.
In the example in Section 3.3, no step value was given, so the index
variable X was incremented by 1 on each pass through the loop. If line 10 in
the example were changed to
10 F O R X = 3 TD 1 0 S T E P 2
the program would execute a loop for each value of X from 3 to 10 by 2s and
would produce the following output on the display screen:
PASS # 1
I HD E X • 3
PASS '2
I HDEX • 5
PASS #3
I HDEX • 7
PASS #4
I HDE X • 9
LOOP F I H I SHED
The loop would be executed four times, with the index variable taking on
values of 3, 5, 7, and 9. At the end of the fourth pass, the index variable
would exceed the specified ending value (9 plus 2 is 11, which is greater
than the ending value of 10), so the loop would end and execution would
continue with the statement following the NEXT in line 60.
3.3 Loops 53
becomes greater than the specified ending value (less than the ending value
if the step value is negative), execution proceeds with the statement
immediately following the NEXT statement.
Naming the index variable in a NEXT statement is optional; if you omit it,
Applesoft automatically repeats the most recently entered loop. If you're
using nested loops (see Section 5.3.3), this means the innermost loop
containing the NEXT statement is repeated.
Helpful Hint: Leaving out the index variable in NEXT statements
makes your programs run slightly faster:
10 FOR G • 1 TO 6
20 P R ili T " W O W , M O M ! "
30 H E XT No index variable necessary.
-
A = 1' B
. 2
A
-
2, B
- 1
A
-
2, B
- 2
A
A -
3, B
3, B - 1
2
Nested loops must not cross each other-that is, each loop must be
completely contained within the body of the next outer loop. Once a loop is
started using a particular index variable, the corresponding NEXT must
name the same index variable (if it names any at all). In the example above,
if lines 40 and 50 were reversed
40 NEXT A Attempts to repeat outer loop
50 NEXT 8 before inner loop is finished.
the program would halt with an error because of the crossed loops.
Combining NEXT Statements: When two or more NEXT statements
occur in a row, you can combine them into a single NEXT statement of
the form
40 NEXT 8 , A
Notice, however, that the index variables must be listed in the reverse
order of their corresponding FOR statements, to avoid crossing loops. The
statement
40 NEXT A , 8
3.4 Subroutines
A subroutine is a section of a program that can be executed on request
from another part of the program. Applesoft has four statements relating to
subroutines:
□ GOSUB (see Section 3.4. 1) directs control to a particular subroutine.
□ RETURN (see Section 3.4.2) sends control back to the statement
following the GOSUB that branched to the subroutine.
□ ON ... GOSUB (see Section 3.4.3) selects one of a number of possible
subroutines, depending on the value of an arithmetic expression.
□ POP (see Section 3.4.4) removes a return address from the top of the
control stack (see the box entitled "How Subroutines Stack Up" later in
this section).
3.4 Subroutines 55
To call a subroutine (request its execution), branch to its first line with a
GOSUB statement. GOSUB differs from an ordinary GOTO (see Section 3.1)
in that it remembers where in the program the subroutine was called from,
so that control can return to that point when the subroutine is finished. The
same subroutine can be called from many different places in the program;
when the subroutine is finished, it sends control back to the statement
following the proper point of call by executing a RETURN statement.
Here's an example to illustrate the idea:
10 F O R Z • 1 TO 1 0 Executes loop ten times.
20 LET X = I HT C RHD < 1 > * 1 0 0 )
Generates a random integer
between O and 99.
30 PR I HT x " I s " ; Displays first part of message.
40 I F X < 5 0 THEH GOSUB 1 0 0 0 : GOTO 6 0
Branches to subroutine at line 1000
if random number is less than 50; on
return, goes to line 60.
50 Gos uB 2 0 0 0 Branches to subroutine at line 2000
if random number is 50 or greater.
60 PR I NT "PASS "" ; Z P R I NT
Counts number of passes through
loop.
70 HEXT Z Repeats loop.
999 E H D Ends program.
1000 P R I H T " L E S S T H A H 5 0 " Prints second part of message for
numbers less than 50.
1 0 1 0 RETURH Returns to statement following
point of call.
2 0 0 0 P R I N T " M O R E T H A H 4 9 " Prints second part of message for
numbers greater than 49.
2 0 1 0 RETURN Returns to statement following
point of call.
The loop in lines 10 to 70 generates a random integer between O and 99,
then calls one of the two subroutines at lines 1000 and 2000, depending on
the value of the random number. Each of the subroutines displays an
appropriate message, then returns control to the statement following the
point of call with a RETURN statement (lines 1010 and 2010). The program
then displays a count of the number of passes through the loop and repeats
the loop from the beginning. When the loop has been executed ten times,
the program ends.
3.4 Subroutines 57
Line 10 calls the first subroutine, at line 1000. This subroutine displays the
first message on the screen, then (line 1010) calls the second subroutine at
line 2000. The second subroutine displays its message, then returns control
(line 2010) to the statement following the point of call in the first
subroutine. The first subroutine then displays another message and returns
control (line 1030) to the statement following its point of call. The final
message is then displayed (line 20) and the program ends. The lines of the
program are executed in the following order:
Line 10
Line 1000
Line 1010
Line 2000
Line 2010
Line 1020
Line 1030
Line 20
Line 30
The program produces the following output on the screen:
F I RST SUBROUT I NE CALLED
SECOND SUBROUT I NE CALLED
BACK AT F I RST SUBROUT I N E
B A C K H OME AGA I N
How Subroutines Stack Up: Applesoft maintains a control stack to
keep track of the return addresses-the points to which control is to
return on completion-for all subroutines in progress. Each time a
GOSUB is executed, the location of the statement following the GOSUB is
pushed onto the top of the stack. When a RETURN statement is
executed, the top entry is popped from the stack and control is directed
to that point in the program. This arrangement ensures that control
enters and leaves subroutines in LIFO (last-in-first-out) order.
Subroutine calls can be nested up to 25 levels deep: that is, you can GOSUB
from a GOSUB from a GOSUB ... 24 times. Attempting to go more than
25 levels deep results in an o u T OF M E M O R Y error. If this error occurs,
you're actually out of stack space, as opposed to program space. Since no
rational BASIC program ever uses such complex nesting, this error usually
means you've got a subroutine accidentally calling itself.
3.4 Subroutines 59
line number in the list.) If the integer value of the expression is O or is
greater than the length of the list, execution continues with the next
statement following the ON ... GOSUB.
The following program illustrates the use of ON ... GOSUB:
10 I HPUT X Gets number from keyboard.
20 O H X G O S U B 1 5 0 , 2 0 0 , 3 1 0 , 3 1 0 , 1 5 0 , 999
Decides where to go, depending on
value of X.
30 I F X • 0 D R X • 6 T H E H P R I H T "VA L U E O UT O F R A HGE ,
P L E A S E R E T Y P E : II Displays message if X out of range.
4 0 GOTO 1 0 Starts again.
1 5 0 P R I H T "V A L U E I S 1 O R 5 "
Control comes here if X = 1 or
X = 5.
1 60 RETURH
200 PR I HT "VALUE I S 2" Control comes here if X = 2.
210 RETURH
310 P R I HT "VA L U E I S 3 D R 4 "
Control comes here if X = 3 or
X = 4.
320 RETURH
999 EHD Control comes here if X = 6.
Compare this program with the example given for the ON ... GOTO statement
in Section 3.2.1. The operation of ON ... GOSUB is very similar to that of
ON ... GOTO, except that ON ... GOSUB remembers where in the program the
subroutine was called from by pushing onto the control stack the location of
the next statement following ON ... GOSUB. Control can then return to that
point with a RETURN statement when the subroutine is finished.
If the integer value of the expression between ON and GOSUB is less than 0
or greater than 255, an I L L E G A L G U A H T I TY error occurs and program
execution halts.
POP
The POP statement removes (pops) the top return address from the control
stack without sending control to that point. This causes the next RETURN
statement to send control back to the point of the second most recent
subroutine call, instead of the most recent.
3.4 Subroutines 61
Resist Temptation: Although it's sometimes tempting to try to get out
of a tight programming situation by using POP, most good programmers
avoid it, because it makes program flow really difficult to follow. If you
find yourself becoming ensnared in convoluted code, 'tis a far better thing
to redesign your program than to resort to the use of POP. Refer to
Chapter 8 for a tutorial on program planning.
Code Meaning
0 NEXT without FOR
16 Syntax error
22 RETURN without GOSUB
42 Out of data
53 Illegal quantity
69 Overflow
77 Out of memory
90 Undefined statement
107 Bad subscript
120 Redimensioned array
133 Division by 0
163 Type mismatch
176 String too long
191 Formula too complex
224 Undefined function
254 Bad response to INPUT statement
255 CONTROL-C interrupt attempted
This program also illustrates another application of POKE 216,0. Notice that
if the error is anything other than a � interrupt (code 255), the
IF ... THEN test in line 21510 sends control directly to the RESUME
statement in line 21540, without executing the ONERR GOTO in line 21530.
The effect of this is to re-execute the statement containing the original
error, but with Applesoft's normal error handling still in effect. This causes
the same error to occur again, but this time Applesoft displays its normal
error message and halts the program. Thus � is the only error
that gets special handling; all other errors produce the same results as if
there were no special error routine.
The END statement halts execution of the program and returns control to
Applesoft's command level. No message is displayed on the screen; program
execution just stops quietly.
999 E H D
An END statement is purely optional at the end of a program. The program
ends by itself, even without an END statement, when it runs out of
statements to execute.
•
•
•
•
•
•
fl,
69
This chapter discusses two important forms of data on which Applesoft
programs can operate: arrays and strings. Both topics were treated briefly in
Chapter 2, "Variables and Arit}unetic," but are covered in more detail here.
□ Section 4.1, "Arrays," deals with collections of related information of any
type (real, integer, or string), referred to by the same name and
distinguished by means of numerical subscripts.
□ Section 4.2, "Strings," describes Applesoft's facilities for manipulating
strings of characters such as words or names: comparing them,
concatenating (chaining) them together, taking them apart, and
converting them to and from numeric values.
4. 1 Arrays
An array is a collection of variables referred to by the same name, usually
holding data items that are related to each other in some logical or
systematic way. The individual variables in the array are called its
elements, and are distinguished from one another by means of identifying
index numbers called subscripts.
An array can be of any type: integer, real, or string. Array names follow the
same rules as simple variable names of the same type. To refer to a
particular element of an array, write the array name followed by one or
more subscripts, separated by commas and enclosed in parentheses. The
subscripts refer to the position of the desired element within the array:
G c6> Element 6 of real array Q.
F r GU R E x c to Element N of integer array
FIGURE%.
NAME s c J - 3 > Element J - 3 of string array
NAME$ .
C O U N T ( S UM % , 2 ) Element (SUM%, 2) of real array
COUNT.
Figure 4-1 shows a real array named R with five elements, numbered 0 to 4.
Element R(0) (pronounced R-sub-zero) holds the value 53, R(l)
holds 27.35, and so on. If the value of variable S is 2, then the
expression R(S) refers to element R(2), whose value is 31.4, and the
expression R(S + 2) refers to element R(4), which holds the value 19.
array R
R (O) - 53
R ( l) - 27.35
R (2) - 31 . 4 -- R (S)
R (3) - 6
R (4) - 19 +-- R (S + 2)
Another example is shown in Figure 4-2, this time a string array named
NAME$ with seven elements, numbered O to 6. Element NAME$(1) holds
the string value "SCOT", NAME$(3) holds the value "BRUCE", NAME$(6)
holds "MEG", and so on. If the value of variable C% is 5, then the expression
NAME$(C%) refers to element NAME$(5), whose value is "J.D.", and the
expression NAME$(C%- 3) refers to element NAME$(2), which holds the
value "BITZEL".
NAME$ (1 ) "SCOT"
4. 1 Arrays 71
4. 1 . 1 The DIM Statement
DIM R C4>
DIM T I TL E $ C 1 0 0 >
DIM HS CJX>
DIM MARKX C 3 , C I S , P + 2>
The DIM (for dimension) statement defines the size of an array and
allocates memory space for its elements. The expressions in parentheses
following the array name give the dimensions of the array. There can be
from 1 to 88 dimensions.
Once an array has been defined in a DIM statement, any reference to that
array with a different number of subscripts, or with a subscript that
exceeds the maximum specified for that dimension in the DIM statement,
causes the program to halt with a BA D S U B S C R I P T E R R O R message.
Arrays are limited in size by the amount of available memory. See
Section H.2 for detailed information on the amount of space required by
each type of array.
Subscripts Start From 0: Since array subscripts in Applesoft begin
with O (not 1 ), there is actually one more than the specified number of
subscripts in each dimension. For example, the array TITLE$ defined in
the second example has 101 (not 100) elements. In the definition
D I M TEST C 1 2 , 3 , S >
array TEST has 312 elements (13 times 4 times 6), not 180 (12 times 3
times 5) as you might expect.
When Applesoft encounters a reference to an array that has not yet been
defined in a DIM statement, it automatically allocates space for
11 subscripts (0 to 10) in each dimension of the array. Later attempting to
redefine the same array with a DIM statement causes an error stop with the
message ? R E D I M ' D A R R A v E R R a R. Defining the same array in more than
one DIM statement, or executing the same DIM statement twice, produces
the same message.
For the newly perplexed, an analogy may be helpful. Think of the array as
an empty egg carton. On the outside is written the word EGGS. When you
open the egg carton, there are a dozen cup-like indentations where the eggs
go-two rows of six cups each-corresponding to the elements of the array.
Each of the cups is identified by a row number, 0 or 1, and a column number
from O to 5 (we're dealing with strange chickens here).
Now suppose you place three eggs in the egg carton, in elements (0,2), (0,5),
and (1,3):
L E T EGGS ( 0 , 2 ) • " E GG "
L E T E GG S < 0 , 5 ) • " EGG"
LET EGGS < 1 , 3 ) s " E GG "
Figure 4-3b shows the result.
4 .1 Arrays 73
You might also elect to use your egg carton to hold small change. If you put
a nickel in position (0,1), a dime in position (1,1), and a quarter in
position (1,4)
L E T EGGS ( 0 , 1 ) • 5
L E T EGGS C 1 , 1 > • 1 0
L E T EGGS ( 1 , 4 ) • 2 5
your carton would look like Figure 4-3c.
�, -
column column column column column column
0 1 2 3 4 5
row ! --+
1 J-+o-1�1 l-� 1�1 EGG
4.2 Strings
A string is a sequence of text characters (letters, digits, and punctuation
marks). Just as you can write numeric constants such as 27 and 2.236 in
your Applesoft programs, you can write string constants by enclosing the
characters in the desired string between double quotation marks:
"ON SALE FOR $49.95"
"Truth is impervious to hissing"
"H2SO4"
"???"
Lowercase Okay: Even though your version of Applesoft may not
understand lowercase letters when you use them in keywords, it allows
you to use them in a string constant, as shown in the second example .
A string variable can hold any string as its value. Its name must end with a
dollar sign ($). Some legal string variable names are
TITLE$
G2$
D$
Until they are given some other value with an assignment statement, all
string variables are preset to the null string.
4.2 Strings 75
Strings and Alphabetical Order: Since letters of the alphabet are
represented by consecutive codes in the ASCII table, comparisons
between strings of alphabetic letters can be used to place the strings in
conventional alphabetical order. For example,
"E" is less than " F"
"ED" is less than "EDGAR"
"EDGAR" is less than "EDWARD"
"EDWARD" is less than "EDWARDS"
"EDWARD" is less than "FRANK"
There are a few surprises, however: since uppercase letters precede
lowercase letters in the ASCII chart,
"Zebra" is less than "aardvark"
And since strings are compared strictly character by character,
"48" is less than "5"
If you want to compare two strings consisting of digits according to the
numbers they represent, use the VAL function. (See Section 4.2.5.)
When executed, this program displays the following output on the screen:
T H E R E A R E 2 7 C H A R A CT E R S I H T H E STR I H G .
If you use as LEN's argument a concatenation of two or more strings with a
combined length of more than 255 (the maximum allowable string length),
your program halts with the message ? STR I HG TOO L O H G E R R O R .
Instead of writing
LEH C A $ + BS + C S >
it's safer to use
LEH C A $ ) + LEH CB$ ) + LEH C C $ )
4.2 Strings 77
The program
1 fJ L E T N A ME S • " C H A R L I E "
2 1! L E T T I TL E S • "DEAR " + NAME S + II
' II
3 1! P R I NT T I TL E $
4 1! P R I NT " H A V E W E GOT A S A L E ! "
displays the output
DEAR CHARL I E ,
H A V E WE GOT A S A L E !
on the screen. The program
1 1! L E T A $ • "GOOD "
2 1! L E T A S • A $ + "G R I E F ! "
3 1! P R I NT A $
displays
G O O D GR I E F !
If the result of a concatenation operation is a string more than
255 characters in length, the program halts with the error message
? S TR I NG T O O L O N G E R R O R .
You can test how long the result of a concatenation will be beforehand by
using the LEN function. For example:
1 1! LET A $ • "HAPPY DAYS"
20 LET L 1 • L EI'! < A S > How many characters in A$?.
31! L E T B S • " A R E H E R E AGA I N "
4 1! L E T L 2 • L EI'! < B S > How many characters in B$?
S il I F C L 1 + L 2 > < 2 5 6 T H E N LET A $ • A $ + B S
If the combined lengths of A$
and B$ are less than 256, combines
the two strings into A$.
i s the string "1234". I f you want to add two strings consisting o f digits
according to the numbers they represent, use the VAL function. (See
Section 4.2.5.)
4.2 Strings 79
4.2.4.2 The MID$ Function
MID$ (for middle) extracts a specified number of characters fr.om a
specified position within a string. The MID$ function takes three
arguments, separated by commas: the string from which the characters are
to be taken, the position within the string of the first character, and the
number of characters desired. For example,
M I D S C " H O W DO I L OV E T H E E ? " , 1 0 , 4)
4 characters beginning at
position 10 in string "HOW DO I
LOVE THEE?"; yields "LOVE."
M I S C H9s , R + 7 , 2 * v
D > 2 * V characters beginning at
position R + 7 in the contents of
string variable H9$,
You can optionally leave out the third argument to MID$. If you don't
specify the number of characters you want, or if the number of characters
you request is greater than the length of the string, MID$ yields all
characters from the designated starting position to the end of the string:
M I D S ( " T H E R E T H E Y G O ! " , 7 ) All characters from position 7 to end
of string "THERE THEY GO!"; yields
"THEY GO!"
M I os < A s , 1 0 > All characters from position 10 to
end of the contents of string
variable A$.
M I D s < " H I TH E R E " , 4 , 2 0 > All characters from position 4 to end
of string "HI THERE"; yields
"THERE."
If the value you give for the starting position or the number of characters in
the substring is a real number, MID$ truncates it to the next lower integer.
If the designated starting point is greater than the length of the string, or if
the number of characters requested is 0, MID$ yields the null string.
The starting position must be between 1 and 255, and the number of
characters between O and 255, or the program halts with the message
? I L L E G A L . Q U A N T I T Y E R R O R . If you omit the dollar sign ($) from the
function name MID$, Applesoft treats MID as an arithmetic variable name,
causing an error stop with the message ? TY P E M r S M A T C H E R R O R .
4.2 Strings 81
4.2.5.1 The STR$ Function
The STR$ (for string) function converts a numeric value into a string
representing that value. For example,
STR $ C - 1 1HJ ) A string representing the
number -100; yields "-100."
STR $ ( 3 . 1 4 1 59 ) A string representing the
number 3.14159; yields "3.14159."
STR$ (MARK> A string representing the numeric
value of real variable MARK.
STR $ C C O U H T X > A string representing the numeric
value of integer variable COUNT%.
A string representing the numeric
value of the expression
B A 2 - 4•A•C.
The string produced by STR$ is in the same format that Applesoft uses to
display or print numbers; see Appendix I for details. For example,
STR S C 1 BB BBB BBB> Yields "100000000."
STR$ (1 BBB BBB BBB> Yields "1E+09."
STRS C - . 83) Yields "-.03."
STR S C - . IHJ 3 ) Yields "-3E-03."
If the numeric value of the argument falls outside the allowable range for
real numbers (-9.99999999E+37 to +9.99999999E+37), the program halts
with the message ? OV E R F L O W E R R O R.
4.2 Strings 83
4.2.5.4 The ASC Function
The ASC (for ASCII) function takes a single string argument and yields the
ASCII code corresponding to the first character in the string. For example,
A s c c D 11 >
II
ASCII code for character D;
yields 68.
A s c c 11 1 11 > ASCII code for character /;
yields 47.
A S C ( e . e . c u mm i n 9 5 " )
11
ASCII code for character e;
yields 101.
Asc c B0 o ASCII code for the first character in
string BO$.
A S C C M I D S O i AME $ , 5 ) > ASCII code for the fifth character in
string NAME$.
If the argument given to ASC is the null string, the program halts with the
message ? I L L E G A L Q U A H T I TV E R R O R .
•
•
85
This chapter is concerned with the ways in which Applesoft programs
communicate with the outside world. Here are described Applesoft's
facilities for getting information into and out of the computer and for
controlling the way information is presented.
□ Section 5.1, "Input," deals with the various statements through which
Applesoft programs receive information for processing.
□ Section 5.2, "Output," describes how programs transfer information to
the "outside world": to the display screen, printers, and so forth.
5.1 Input
The input statements discussed in this section enable Applesoft programs to
receive information for processing, either from the keyboard or from a
peripheral device connected to the computer:
□ The IN# statement (see Section 5.1.1) controls the source from which
the computer receives its input.
□ The INPUT statement (see Section 5.1.2) accepts a line of input from the
current input device.
□ The GET statement (see Section 5.1.3) reads a single character from the
current input device.
□ The READ (see Section 5.1.4), DATA (see Section 5.1.4), and RESTORE
(see Section 5.1.5) statements are used to read information from within
the running program itself.
□ A few miscellaneous input facilities (see Section 5.1.6) are available for
reading the hand controls and, in the case of the Apple II, Apple II Plus,
and Appie Ile, for reading information from a cassette tape recorder.
86 Chapter 5: Input/Output
When Applesoft is started up, it is set to receive input from the keyboard.
Executing an IN# statement with a number from 1 to 7 instructs Applesoft
to receive input instead from the peripheral input device (such as a modem)
connected to the designated port or slot. Using number O reestablishes the
keyboard as the current input device. For example, the following program
fragment reads a single character from the device connected to port 2, then
reestablishes keyboard input:
5 1 il l i'i # 2 Accepts input from port 2.
GET statement: see Section 5.1.3 5 2 il GET A$ Reads one character from port 2.
5 3 il I i'i # il Accepts future input from keyboard.
Notice that the character # is part of the keyword IN# and cannot be
omitted.
If You Use DOS or ProDOS: If you have DOS or ProOOS active, any
IN# or PR# (see Section 5.2.1) statement must be set up as a disk
operating system command to prevent the disk operating system from
being disconnected. In that case, the example would look like this:
5 1 il P R l l'i T C H R $ C 4 ) ; " 11'i # 2 "
5 2 il GET AS
5 3 il P R ll'i T C H R $ C 4 ) ; " ll'i # il "
See the manual that came with your disk operating system for more
details .
..&.Warning If the port designated in an IN# or PR# statement contains a disk
controller card, Applesoft attempts to restart the system from the disk
contained in drive 1 connected to that port. When you do this on purpose,
it's the usual way of restarting the system from within Applesoft; when
you do it by mistake, it can be a catastrophe. So be careful!
If no input device is connected to the port designated in an IN#
statement, the system hangs. To recover, use I CONTROL H R ESET 1. Using a
port number between 8 and 255 causes unpredictable and possibly
aberrant behavior.
Using a port number less than O or greater than 255 in an IN# statement
stops the program with an error message.
5 . 1 Input 87
5.1 .2 The INPUT Statement
I N P UT PR I CE
I HPUT M H T H X , DA Y X , Y E A R X
I HPUT "WHAT I S Y O U R P A S SW O R D ? '' ; P A S SW D $
I H P UT "" ; X
The INPUT statement accepts a line of input (which must be terminated by
I RETURN I) from the current input device, specifying values to be assigned to
one or more variables. The variables are listed in the INPUT statement,
separated by commas.
The INPUT statement can optionally include a message to be displayed or
printed on the current output device, prompting the user for the desired
input. If present, the prompting message must be given as a string constant
immediately following the keyword INPUT and followed by a semicolon to
current output device: see Section 5.2.1 separate it from the list of variable names.
The specified prompting string is reproduced exactly as written; if
displayed on the screen, it is immediately followed on the same line by the
cursor. If the prompting message is omitted from the INPUT statement, a
question mark (?) is displayed; the question mark can be suppressed by
supplying a null string as the prompting message. For example,
10 P R I HT "WHAT I S Y O U R A G E , P L E A S E ? "
Displays prompting message on its
own line.
20 I HPUT AGE Prompts with ? and waits for
response.
30 I HPUT "YOUR STREET HAME ? " ; ST$
Displays prompting message on
same line as cursor and waits for
response.
40 P R I HT " P L E A S E T Y P E Y O U R F I R S T A H O L A S T H A ME S , " ;
" S E P A R A T E D BY A C O MMA : I I Displays prompting message on its
own line.
S Iil I H P UT "" ; rn• , LH$ Suppresses ? and waits for two
responses separated by a comma.
The INPUT statement in line 20 above displays a question mark to prompt
the user for input, followed by the cursor. The INPUT statement in line 30
displays the prompting message Y O U R STR E E T H A M E ? instead of the
question mark, again followed by the cursor. The INPUT statement in
line 50 displays the cursor only, with no question mark and no prompting
message of any kind.
88 Chapter 5: Input/Output
The INPUT statement can be executed only from within a program; you
can't use this statement in immediate execution.
5.1 Input 89
5.1 .2.2 General Rules for Input
Users of your program should know the following general rules for input:
□ If the user types a colon (:) as part of an input line, the remainder of that
input line is ignored. The ASCII null character � has the
same effect.
□ An INPUT statement can be interrupted by � (see
Section 1 .3.2), but only if it is the first character typed on an input line.
In that case, the program halts when I RETURN I is pressed at the end of
that line. A � that is not the first character of the input line
is treated as part of the input, the same as is any other character.
□ If the user types an input line longer than 255 characters, the whole line
is canceled and has to be retyped from the beginning (the Apple beeps
from about the 245th character, but no message is displayed). A response
of more than 239 but fewer than 255 characters is truncated to
239 characters with no warning message displayed.
90 Chapter 5: Input/Output
□ In general, control characters cause problems and should not be used in
responding to INPUT statements. The following characters cannot be
included in the response:
� Equivalent to G or the backspace key.
� Equivalent to I RETURN 1.
I CONTROL H]] Cancels the input line.
� ASCII null character; causes remainder of input line to
be ignored.
□ The value supplied for a string variable must be a single string or a
constant; it cannot be a string expression involving concatenation,
LEFT $ , MID$ , RIGHT $ or other string operations. Responses such as
AS + BS
L E F T S C MD N TH S , 3 )
R I GH T S C N A ME S , L - C F L + 2>>
are accepted exactly as typed, character for character (up to the first
comma), and are not evaluated as string expressions.
5.1 Input 91
□ Numeric responses consist of the following elements. Any or all of these
elements can be omitted, except that the sign or value of the exponent
cannot appear unless preceded by the letter E. Even forms such as + E
and .E are accepted, and are interpreted as 0. Those that are included
must be given in the order listed:
1. A sign ( + or -)
2. One or more digits
3. A decimal point (.)
4. One or more digits
5. The letter E for scientific notation
6. A sign (+ or -) for the exponent
7. One or more digits
□ If the first nonspace character is a comma, colon, or I RETURN I, the
response is interpreted as O and program execution continues. A response
beginning with � is invalid.
□ The following control characters have special meanings. A response
containing any other control character, in any position, is invalid.
� Equivalent to E) or the backspace key
� Equivalent to the I RETURN I key
! CONTROL ffK} Cancels the input line
� ASCII null character; causes remainder
of input line to be ignored
□ The value supplied for a numeric variable must be a single number; it
cannot be a numeric expression involving arithmetic operations or
function calls. Responses such as
1 /2
BA2 - 4 * A * C
SQR C 2 )
are invalid because of the non-numeric characters.
Programming Tip: It's a good idea to use string variables to accept all
numeric inputs, using the VAL function (see Section 4.2.5) to convert
them to numeric values. This makes it easier to detect and deal with user
errors and to display alternate prompting messages.
92 Chapter 5: Input/Output
5.1 .2.5 An "Input Anything" Routine (
The INPUT statement interprets the colon and the comma (and sometimes
the quotation mark) as special symbols and rejects anything typed after
them in the input line. Here's what you can use if you anticipate that your
user's response may include any of these characters.
The following Applesoft subroutine uses the POKE statement (see
Section 7.1.2) to store a special machine-language routine in the computer's
memory, one byte at a time, beginning at address 768. The
machine-language routine accepts all characters in the input, including
colons, commas, and quotation marks, without "censoring" them, and
assigns them, character by character, to a string variable for further
processing. (The following line numbers are arbitrary; you can locate this
subroutine anywhere you like in your program.)
6 2 frl frlfrl R E M S E T U P " I N P U T A N YTH I HG" R O UT I N E
6 2 frl 1 frl LET I N $ • "X" IN$ must be first variable created.
6 2 frl 2 frl F O R J = 768 T O 7 9 frl These are memory addresses where
machine language is to be stored.
6 2 frl 3 frl READ I Gets a byte of machine language.
6 2 frl 4 frl POKE J, I Stores it at next location.
6 2 frl 5 frl NEXT J Goes back for next byte.
6 2 frl 6 frl DATA 1 6 2 , frl ' 3 2 , 1 1 7 , 2 5 3 , 1 6 frl , 2 , 1 3 8 , 1 4 5 ,
1 frl 5 , 2 frl frl , 1 69 , frl ' 1 4 5 , 1 frl 5 , 2 frl frl , 1 69 , 2 , 1 4 5 ,
1 frl 5 , 6 , 5 7 , 2 1 3 These are the actual bytes of
machine language.
6 2 frl 7 frl RETURN Returns to statement following
point of call.
The DATA statement (see Section 5.1 .4) containing the machine language
must be reproduced in your program exactly as shown.
The following subroutine uses the CALL statement (see Section 7.1.3) to
call the machine-language routine at address 768. (Again, this subroutine
can be located anywhere in your Applesoft program, not necessarily at line
number 63000.)
63 frlfrl frl R E M C A L L " I N P U T A N Y T H I HG" R O UT I N E
6 3 frl 1 e C A L L 768 Calls machine-langu�ge routine.
6 3 frl 2 frl I H $ • M I D $ < I N $ , 1 > IN$ now holds the input that the
machine-language routine accepted.
63 e 3 e RETURN Returns to statement following
point of call.
5.1 Input 93
To accept a line of input from the user, instead of using a statement such as
1 1Hl I NPUT 5 $
94 Chapter 5: Input/Output
Here's an example of a program fragment using GET:
310 P R I N T " P R E S S T H E ' Y ' K E Y TO GO O H : ";
Prompts user for response
semicolon: see Section 5.2.2 (semicolon keeps cursor on same
line).
32 0 GET A s Waits for user to press key.
330 I F A $ < > "Y" AHO A $ < > "y" THEN 320
Keeps cycling until user presses
correct key.
34 0 P R I HT Moves cursor to new line (cancels
effect of semicolon from line 310).
350 PR I HT "THAHK YOU" Politeness from machines is always
welcome.
The GET statement can be executed only from within a program; you can't
use this statement in immediate execution.
If typed in response to a GET, � is treated like any other
character; it does not interrupt program execution.
Following GET With an Operating System Command: A disk
operating system command issued immediately after a GET is not
recognized. For such commands to be executed properly, you must issue
a I RETURN I character immediately after the GET. An easy way to do this
is with an empty PRINT statement:
P R I NT
5.1 Input 95
5 . 1 .4 The READ and DATA Statements
READ PR I CE
READ A , B , MX C I > , J X , S $ C 2 * J - 1 ) , T S
DATA 1 2 . 9 , H I H O , 1 68
DATA 2 . 236
The READ and DATA statements are used to read information from within·
the Applesoft program itself, rather than from the keyboard or another
input device. There can be any number of DATA statements in a program,
each containing a list of one or more items of information (numbers or
strings) following the keyword DATA and separated by commas. All of the
DATA statements in the program are considered to form one long list of
items, in sequential order by line numbers; each READ statement reads one
or more items from this list.
Each time it executes a READ statement, Applesoft remembers the last
item read from the DATA list. The next READ always begins with the next
item in the list. There is no way to back up or skip forward in the DATA list,
but you can start over from the beginning of the list with the RESTORE
statement (see Section 5.1.5).
An attempt to read past the end of the DATA list halts the program with a
message such as ? O U T O F D A T A E R R O R I N 1 4 65 identifying the line
number of the READ statement in which the error occurred. Leaving part of
the DATA list unread at the end of the program does not cause an error.
The items in a DATA statement are separated by commas and follow the
usual rules for numeric and string input, except that a DATA statement
cannot contain an unquoted colon (:). The number of items in each DATA
statement is limited only by the length of the program line. A DATA
statement can appear anywhere in your program; it need not precede the
READ statement that uses it. There is no limit to the number of DATA
statements in a program.
96 Chapter 5: Input/Output
Here's a sample program showing the use of the READ and DATA
statements:
10 DATA "GO W E S T , Y O U N G M A N "
Item containing a comma; OK
between quotation marks.
20 DATA 3 . 1 4 1 5 9 , 2 , " S AM" Mixed types in same DATA
statement.
30 READ A $ , B Reads GO WEST, YOUNG MAN into
string variable A$ , and 3.14159 into
real variable B; notice that these
items come from two different
DA TA statements.
40 READ ex , D$ , E $ Reads 2 into integer variable C%,
SAM into string variable D$ , and
THE "WORLD" IS FLAT into string
variable E $ ; begins with next item
following previous READ statement.
SB DATA THE "WORLD" I S FLAT
Item containing quotation marks;
notice that this item follows the
READ statement that uses it.
60 PR I NT E S Displays T H E " W O R L D " I S
F L A T.
70 PR I NT A $ Displays G O W E S T ' Y O U N G MAN.
80 D A T A 98 . 6 , 3 7 , -273 . 1 6 These items never read.
90 END
Null items in a DATA statement are interpreted as O or the null string,
depending on the type of variable to which they are assigned in a READ
statement. A null item is read whenever there are no nonspace characters
between
□ the keyword DATA and the end of the program line
□ the keyword DATA and the first comma
□ two consecutive commas
□ the last comma and the end of the program line.
Thus the statement
D A TA , ,
5.1 Input 97
An attempt to read a string value in a DATA statement with a numeric
variable in a READ statement causes a syntax error. Numeric values can be
read into string variables, but must be evaluated with the VAL function (see
Section 4.2.5) before they can be used as numbers.
Control Characters in DA TA Statements: The characters
I CONTROL H:B], �. I CONTROL f-lK], and �
cannot be embedded in a DATA statement. Any other control character
typed into a DATA statement is treated as an ordinary character and
becomes part of the input. A � character in a DATA
statement does not interrupt the program.
The READ statement can be executed only from within a program; you
can't use this statement in immediate execution.
98 Chapter 5: Input/Output
There is no way to reposition the DATA list to a specific desired item or line
number. The only other Applesoft statement that affects the positioning of
the DATA list is RUN (see Section 1.2.4), which also restarts the list from
the beginning.
This section covers Applesoft's facilities for dealing with the remaining
input features of the Apple II: the hand controls and cassette tape input.
Refer also to Appendix 0.
5.1 Input 99
If the argument given to PDL is less than O or greater than 255, the program
halts with the message ? I L L E G A L Q U A HT I T Y E R R O R . If the argument is
between 4 and 255, or if no hand control of the designated number is
connected, the results are unpredictable.
Consecutive Readings: If your program reads two hand controls in
consecutive statements, the reading from the first hand control may
affect the reading from the second. To obtain more accurate readings,
allow several program lines between calls to PDL or use a short delay loop
such as
FOR X • 1 TD 10 : HEXT X
PR# 1
PR# X
PR# SLOT - J
The PR# statement specifies the destination to which the computer sends
subsequent output. The expression following the keyword PR# should
evaluate to a number between O and 7, designating the port to which output
is to be sent.
When Applesoft is started up, it is set to send output to the display screen.
Executing a PR# statement with a port number from 1 to 7 instructs
Applesoft to send output instead to the peripheral output device (such as a
prin�r or modem) connected to the designated port. A port number of 0
reestablishes the display screen as the current output device. For example,
the following program fragment writes a string of characters to the device
connected to port 1, then reestablishes screen output:
s 1 fil P R , 1 Sends output to device in port 1.
6 2 fil P R I M T z s Writes contents of string variable Z$
to device in port 1.
63 fil P R , fil Sends future output to screen.
Notice that the character # is part of the keyword PR# and cannot be
omitted.
S O T H E R E ' S A B L A N K L I N E O N THE S C R E E N
To eliminate the blank line, add a semicolon to the end of line 10:
10 P R I NT "TH I S M E S S A G E H A S P R E C I S E L Y 4 0
C H A R A CTE R S " ;
Now you get this:
TH I S M E S S AGE H A S P R E C I S E L Y 4 0 C H A R A CT E R S
S O T H E R E ' S A BL A N K L I N E O N T H E S C R E E N
The second line of this message i s now a lie.
A statement such as
PR I NT A $ + 8$
causes a halt with the message ? S TR I N G T O O L O N G E R R O R if the
combined length of the concatenated strings is greater than 255 characters.
However, you can print the apparent concatenation regardless of length by
using a semicolon:
PR I NT A $ ; 8$
When an item in the PRINT list i s followed by a comma, the cursor or print
head is advanced to the next available tab position: column 17 or 33 of the
current line or column 1 of the next line. The next item written begins at
the tab position. A series of consecutive commas advances the cursor or
print head a corresponding number of tab positions. A comma at the end of
A • 5 . 35
GX • 1 6
Ct • FRED
85 . 6
Abbreviation for PRINT: You can use a question mark (?) as an
abbreviation for the keyword PRINT; if you use it, it appears as P R I HT in
a program listing. If you type
1 ll ll ? A$
L I ST
Applesoft displays
1 11 11 PR I HT A $
displays
1 . 2 3 4 5 6 7 88
on the screen.
Integers are always converted to real form before being used in arithmetic
calculations, and the results are converted back to integer form when
assigned to an integer variable. Conversion from real to integer form is by
truncation to the next lower integer, not by rounding to the nearer integer.
Applesoft displays and prints numbers according to the following rules:
□ If the number is negative, it is preceded by a minus sign (-); if it is O or
positive, no sign is used.
□ If the number is an integer with an absolute value from O to 999999999, it
is formatted as an integer.
□ If the number is not an integer and its absolute value is between .01 and
999999999.2, it is formatted with a decimal point in the usual way.
□ In all other cases, the number is formatted in scientific notation. (See
Table 5-1.)
Table 5-1 shows examples of the formats used for displaying and printing
numbers.
scientific notation: the representation of The format Applesoft uses for scientific notation is shown in Figure 5-1.
numbers in terms of powers of 10
I
SX .
I
X X X X X X X X ESDD
V each x is a digit
sign of exponent
digits of exponent
A sign is shown only if the number is negative. There is always exactly one
nonzero digit before the decimal point and up to eight digits after it, with
trailing zeros suppressed. There are never any leading zeros; the digit before
the decimal point is always nonzero. If there is only one digit to print after
all trailing zeroes are suppressed, no decimal point is shown. The letter E
(for exponent) is always followed by a sign and a two-digit exponent. The
value of a number represented in this form is the number before the E
times 10 raised to the power after the E. For example,
P R r MT 35 * 345 14 A Yields l.18450085E+37.
P R I M T - 3 . 1 4 1 5 9 * 567 5 Yields -1.84104669E+ 14.
A
l lO Chapter 5 : Input/Output
5.2.4.5 The TAB Function
The TAB function is used in PRINT statements (see Section 5.2.2) to
advance the cursor to a specified horizontal position measured from the
beginning of the current output line. The numeric argument given to the
function specifies the position to which the cursor is to be moved. If this
value is a real number, Applesoft truncates it to the next lower integer.
The TAB function can be called only from within a PRINT statement. TAB
differs from SPC (see Section 5.2.4.2) in that it advances the cursor (or print
head, if the current output device is a printer) to a specific horizontal
position from the beginning of the current line, rather than a specified
number of columns from the current cursor position. If the cursor is
advanced past the right edge of the screen or text window, it returns to the
beginning of the next line and continues advancing. For example, assuming
the text window is set to the full screen and the cursor is initially at the left
edge, the statements
1 1!l PR I NT TAB ( 1 5 ) ; "THE F L E ET ' S I N ! "
2 1!l P R I N T T A B C 1 1!l ) ; " H E L L O " ; T A B C 3 1!l ) ;
"TH E R E , " ; TAB ( 4 5 ) ; " S A I L OR ! "
Notice how the output of line 20 wraps around when it reaches the edge of
the screen (column 40).
TAB Moves Forward Only: Unlike the HTAB statement, which moves
the cursor to an absolute horizontal position from the left edge of the
screen or the text window, TAB moves the cursor in a forward direction
only. If the specified tab position is less than the current cursor position,
TAB has no effect; it never moves the cursor to the left on the current
line (use HT AB for this purpose).
If TAB is the last item in a PRINT statement, Applesoft acts as if the
statement ended with a semicolon. The cursor is left at the specified tab
position; no new line is started. The next item displayed begins at the tab
position.
The argument given to TAB must be in the range 0 to 255 or the program
halts with the message ? I L L E G A L Q U A N T I TY E R R O R . An argument
value of 0 moves the cursor to 256 positions from the beginning of the
current line.
1 12 Chapter 5: Input/Output
80-Column Text Card Users: If your computer is an Apple II, an
Apple II Plus, or an early Apple Ile, HTAB is designed to operate with a
40-column screen only. If you attempt to advance the cursor beyond
column 40, it wraps around to the next line, even if you have the Apple II
80-Column Text Card installed and running in "active 80" mode. To tab to
a position between columns 41 and 80, use
POKE statement: see Section 7.1.2 POKE 1 4 03 , XX
where XX is the number of the column to which you want to tab. See
Section F.1 and the BO-Column Text Card Manual for more
information.
The column number specified to HTAB must be in the range 0 to 255 or the
program halts with the message ? I L L E G A L Q U A H T I TY E R R O R . A value
of 0 moves the cursor to 256 positions from the beginning of the current line.
A Programming Tip: Many programmers find HTAB to be more
convenient to use than TAB, because it is an independent statement and
need not be embedded in a PRINT statement. This makes it easier to
change, if necessary, during program development.
1 14 Chapter 5: Input/Output
5.2.4.9 The INVERSE Statement
I NVERSE
The INVERSE statement causes subsequent text output to be displayed in
black-on-white instead of the usual white-on-black (where white means the
phosphor color of your display, whatever that is). The normal
white-on-black display can be restored with the NORMAL statement. (See
Section 5.2.4.11.) For example,
10 I HVE R S E Sets inverse display.
2 0 PR I NT "BLACK - O H -WH I TE " Displays BLAC K - O H - WH I TE in
black-on-white.
3 0 NORMAL Restores normal display.
4 0 P R I NT "WH I TE - O M -BLACK" Displays wH I TE - O M -BLACK in
white-on-black.
INVERSE affects only subsequent output characters sent to the screen with
PRINT statements. It has no effect on characters already on the screen or
on keyboard input "echoed" to the screen. Note: lowercase letters can be
displayed in inverse video only when the 80-column card is active.
Don't overdo it: INVERSE is most effective when you use it sparingly.
5.2 Output 1 15
When FLASH Flops: FLASH doesn't work on characters with ASCII
codes (see Section 4.2.1 and Appendix C) above 95, the most important of
which are the lowercase letters ; instead of making them flash, it turns
them into gibberish.
FLASH doesn't work at all if you have an Apple Ile, or an Apple Ile with
the Apple II SO-Column Text Card installed and running in "active 80"
mode.
FLASH is most effective when used very sparingly. Reserve it for only the
most important messages or unusual uses. Cavalier use of FLASH has been
known to drive users to delirium.
1 16 Chapter 5: Input/Output
5.2.4. 1 2 The SPEED = Statement
SPEED• 255
SPEED• X
SPEED• Z - 6 * F
The SPEED= statement sets the rate at which output characters are sent to
the display screen or other output device (such as a printer). The slowest
rate is O; the fastest is 255. The normal speed setting (if you don't do
anything to change it) is 255. For example,
1 1! SPEED• 0 Sets slowest possible speed.
20 P R I HT "THE TORTO I S E " Displays T H E TORTO I S E slowly.
30 SPEED• 2 5 5 Restores normal speed.
40 P R I HT "THE H A R E " Displays THE H A R E quickly.
SPEED Is Not a Variable: Notice that the equal sign is part of the
keyword SPEED=; it doesn't represent an assignment to a variable
named SPEED. A statement such as
LET SPEED • X
causes a syntax error. The only way to find out the current speed setting
is to keep track of it yourself with a variable, as in the following example:
11! LET X • 250 Sets initial value for speed.
20 SPEED• X Sets speed to value of X.
30 P R I HT " C U R R E NT S P E E D I S " ; X
Displays current speed.
40 L E T X • X - 25 Decreases value of X by 25.
50 I F X > • 0 THEH GOTO 20 Repeats until X becomes negative.
60 SPEED• 255 : EHD X is too low; ends the program.
The speed setting is not reset to its normal value by RUN, CLEAR, or
I CONTROL H RESET 1.
The speed setting specified to SPEED= must be in the range O to 255 or the
program halts with the message ? I LLEGAL QUA HT I TV ERROR.
SPEED= has no effect on graphics.
This section covers Applesoft's facilities for dealing with the remaining
output features of the Apple II: the built-in speaker, annunciator outputs,
utility strobe, and cassette tape output. Most of these features are controlled
by means of PEEK and POKE (see Sections 7.1.1 and 7.1.2); details can be
found in Appendix F. The annunciators and utility strobe are seldom used,
and are mentioned here just for the sake of completeness.
5.2 Output 1 19
Chapter 6 Graphics
•
•
121
This chapter describes Applesoft's facilities for creating, changing,
displaying, and storing both low- and high-resolution graphic designs:
□ Section 6.1, "Low-Resolution Graphics," deals with 16-color graphics on a
40-by-48 grid.
□ Section 6.2, "High-Resolution Graphics," deals with 6-color graphics on a
280-by-192 grid.
□ Section 6.3, "Shape Tables," discusses the use of shape tables for
animation sequences.
□ Section 6.4, "Graphics in Text Mode," discusses MouseText, a set of
graphics you can use in text mode.
6. 1 Low-Resolution Graphics
6. 1 . 1 The GR Statement
GR
The GR (for graphics) statement instructs the computer to display
low-resolution graphics. If the screen has been displaying text, it is changed
from 40 (or 80) columns by 24 lines of text to 40 columns by 40 rows of
graphics, with space for four lines of text at the bottom. (Text display can
be restored with the TEXT statement-see Section 5.2.4.) GR clears the
screen to black, moves the text cursor to the beginning of the bottom line
(line 24), clears any text window that may have been set, and sets the
low-resolution display color to O (black).
Code Color
0 Black
1 Magenta
2 Dark blue
3 Violet
4 Dark green
5 Gray 1
6 Medium blue
7 Light blue
8 Brown
9 Orange
10 Gray 2
11 Pink
12 Green
13 Yellow
14 Aqua
15 White
P L OT 2 0 , 1 2
PLOT X - 6 , Y + 2
P L O T T H E T A * 4 0 / C 2 * P I > , 2 4 - C S I N C TH E T A >
* 23)
The PLOT statement places a block of the current low-resolution display
color at a specified position on the screen. The first expression following the
keyword PLOT specifies the column in which the block is to be plotted
(numbered O to 39, from left to right); the second expression, separated from
the first by a comma, designates the row (numbered O to 39 for mixed text
and graphics, 0 to 47 for full-screen graphics, from top to bottom). For
example, the following program plots a block of pink in column 20, row 2 of
the screen:
1 0 GR Displays low-resolution graphics.
2 0 COLOR • 1 1 Sets display color to pink.
3 0 PLOT 2 0 , 2 Plots a block of pink in column 20,
row 2.
Figure 6-1 shows the system of coordinates used to designate positions on
the low-resolution graphics screen. Position 0,0 is the top-left corner and
position 39,0 the top-right. When displaying mixed graphics and text, the
bottom-left corner is position 0,39 and the bottom-right is 39,39; in
full-screen graphics, the bottom-left corner is 0,47 and the bottom-right
is 39,47.
0, 39 39, 39
(or 0, 47) ._____________, (or 39, 47)
The VLIN (for vertical line) statement draws a vertical line on the screen in
the current low-resolution display color (see Section 6.1.2). The two
expressions following the keyword VLIN, separated by a comma, designate
the rows in which the line is to begin and end; the expression following the
keyword AT specifies the column in which the line is to be drawn. The first
end point may be less than, equal to, or greater than the second. For
example,
1 8 GR Displays low-resolution graphics.
2 8 COLOR • 4 Sets color to dark green.
3 8 VL i l'I 1 8 , 3 8 A T 2 8 Draws a vertical green line in
column 20 from row 10 to row 30.
VLIN in Text Instead of Graphics: If you use VLIN while displaying
text instead of graphics, or if part of the line being drawn goes beyond
row 39 while displaying mixed graphics and text, Applesoft displays text
characters instead of blocks of color. For example, if line 10 were changed
to
18 TEXT
the result would be a row of flashing o's and a dollar sign instead of a bar
of dark green.
A column coordinate outside the range O to 39 or a row coordinate outside
the range O to 47 causes the program to halt with the message ? I L L E GA L
Q U A N T I TY E R R O R .
The VLIN statement has no visible effect if you use it while displaying
high-resolution graphics.
There are two separate regions in the Apple H's memory, designated page 1
and page 2, that can be used for displaying high-resolution graphics. Each
consists of 53,760 points (280 columns by 192 rows) in six colors. This
section describes the facilities available in Applesoft for using
high-resolution graphics:
□ The HGR statement (see Section 6.2.1) instructs Applesoft to begin
displaying page 1 of high-resolution graphics.
□ The HGR2 statement (see Section 6.2.2) instructs Applesoft to begin
displaying page 2 of high-resolution graphics.
□ The HCOLOR= statement (see Section 6.2.3) controls the colors
displayed on the high-resolution screen.
□ The HPLOT statement (see Section 6.2.4) plots individual points and
lines on the high-resolution screen.
Section 6.2.5 tells how to protect your programs and high-resolution
graphics from overwriting each other in the computer's memory.
.A.Warning If you use the reserved word HGR as the first three characters of a
variable name, the HGR statement may be executed before a syntax error
is detected. For example, executing the statement
HGR I P • 4
unexpectedly turns on high-resolution graphics and may destroy part of
your program.
For More Information: If you intend to use HGR with an Applesoft
program longer than about 6000 (decimal) bytes, see Section 6.2.5 on how
to protect your program and graphics from overwriting each other.
See Section F.3 for more information on the use of the various text and
graphics memory pages, and Section H.l for the memory locations
occupied by the high-resolution graphics pages. See your computer's
reference manual for further technical information on the Apple II's
graphics display capabilities.
Code Color
0 Black 1
1 Green
2 Violet
3 White 1
4 Black 2
5 Orange
6 Blue
7 White 2
To draw a line with HPLOT, specify the starting and ending points,
separated by the keyword TO. The next example draws a white line across
the screen:
1 0 HGR Displays high-resolution graphics.
20 H C O L O R • 3 Sets display color to white l.
3 8 H P L O T 0 , 5 8 TO 2 7 9 , 58 Draws a line across row 50.
You can draw a series of connected lines in the same HPWT statement by
using a series of TO clauses. Each line begins where the last one ended. The
following program, for example, draws a rectangle, as illustrated by the
solid lines in Figure 6-3:
1 8 HGR Displays high-resolution graphics.
28 H C O L O R • 3 Sets display color to white 1.
38 H P L O T 7 8 , ◄ 8 TO 2 1 8 , ◄ 8 TO 2 1 8 , 1 2 8 T O 7 8 ,
1 2 0 TO 1 0 , ◄ 8 Draws a rectangle.
The two high-resolution graphics pages lie pretty much in the center of
Apple II memory allocation: see things: page 1 resides at memory addresses 8192 to 16383
Section HJ (hexadecimal $2000 to $3FFF) and page 2 at addresses 16384 to 24575
(hexadecimal $4000 to $5FFF). Because Applesoft program storage begins
at location 2048 (hexadecimal $800) and works its way up, it's easy for your
program and graphics to get in each other's way. For example, if you're
using the HGR statement (see Section 6.2.1) to display page 1 of
high-resolution graphics, you have only 6144 bytes of program and variable
space (8192 minus 2048) before your program overwrites the graphics area.
This section tells how to prevent them from colliding.
One way to protect your program and graphics from each other is to use the
HIMEM: statement (see Section 7.2.1) to set the upper limit of program
memory at 8192. This is a reasonable method to use for short programs; but
Applesoft tends to use a lot of memory, and longer programs would soon run
out of space.
Another method that allows the program a bit more breathing room is to use
the second page of graphics instead of the first (HGR2 instead of HGR). This
has the benefit of starting the graphics at a higher memory location, so you
can set HIMEM: to 16384 instead of 8192, allowing 14336 bytes (16384
minus 2048) for your program and variable space. The disadvantage of this
method is that you lose the four lines of text at the bottom of the screen,
which are available with HGR but not with HGR2.
A third method, probably the best for long programs with lots of variables, is
to use the wizardry of the POKE statement to change the start, instead of
the end, of Applesoft's program storage space. The following statements
start program and variable storage above graphics page 1, beginning at
address 16384 (hexadecimal $4000):
POKE 1 03 , 1
P O K E 1 0 4 , 64
P O K E 1 63 8 4 , ll
These statements start program and variable storage above high-resolution
page 2, beginning at address 24576 (hexadecimal $6000):
POKE 1 03 , 1
P O K E 1 0 4 , 96
P O K E 2 4 5 7 6 , ll
bit number: !7 6 5 4 3 2 1 0 !
specifies: D D P D D P D D
if DD = 00 move up
= 01 move right
= 10 move down
= 11 move left
if P = 0 don't plot
= 1 plot a point
Notice that the last section in each byte (the two high-order bits, labeled C
in the figure) does not include a P bit. The value of P in such a section is
always assumed t,o be O (don't plot); thus section C can only specify a move
without plotting.
b.
c.
Now you're ready to code the plotting vectors as a shape definition table.
Figure 6-6 gives the binary codes corresponding to each possible vector. For
each vector in the shape, determine the proper bit code and place it in the
next available section in the table, as shown in Figure 6-7. If the code won't
fit (for instance, the vector in section C can't plot a point) or is a 00 (or 000)
at the end of a byte, then just fill that section with zeros.
I
vector code
t 000
-
-+ 0()1 or 0l mo,e oo!J
l 010 or 10
01 1 or 1 1
-t 100
1 ... ... -.
-l
101
1 10
lll
-'t -'f
section C B A C B A
byte 0
010
l
lll
- -t
2
100
3
-lt
01 100
4
101
-t
..,;.,.
i 010 101
-l
110 1 10
011 1 10
lll
00 000 000 - denotes end of shape
definition
cannot plot
or move up
The final step is to convert the binary codes representing the plotting
vectors into hexadecimai fonn so you can type them into the computer.
Binary Hex
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
__
bytes
section
byte 0
_,......___0 0 1 0
C B A
=
recoded in hex
12
000 1
I 00 1 1 1111 = 3F
2 00 1 0 0000 = 20
3 0110 0100 = 64
4 0010 1 10I = 2D
5 000 1 0101 = 15
6 00 1 1 0110 = 36
7 000 1 1 1 10 = IE
8 0000 011 1 = 07
9 0000 0000 = 0 0 - denotes end of shape definition
_.. ,_,,
hex: digit 1 digit 2
. . .
. . .
+2n lower 2 digits Dn: index to first byte of shape
}
+2n + 1 upper 2 digits definition #n, relative to S
l
S + DI first byte
shape definition # 1
last byte = 00
S + D2 first byte
S + Dn first byte
last byte = 00
•Warning If you execute DRAW without first loading a shape table into memory,
the system may hang (use I CONTROL H RESET I to recover), or Applesoft
may draw random shapes anywhere in the high-resolution graphics area
of memory (locations 8192 to 24575 decimal), whether or not HGR or
HGR2 has previously been executed. This can have disastrous
consequences if your program is longer than about 6000 bytes.
The XDRAW statement works exactly the same as DRAW, except that the
color used to draw the shape is the complement of the color already existing
at each point plotted. The following pairs of colors are complements:
□ black and white
□ violet and green
□ blue and orange
XDRAW is most commonly used to erase a previously drawn shape. The
following program, which assumes that a shape table has already been
loaded into memory (see Section 6.3.1.5), illustrates the point by drawing
and then erasing the same shape, leaving the screen blank:
1 8 HGR2 Displays full-screen high-resolution
graphics.
2 8 HCOLOR• 3 Sets color to white 1.
3 8 ROT• 8 Orients shape as originally defined.
4 8 SCALE • 5 Enlarges shape five times.
5 8 DRAW 1 A T 5 8 , 1 8 8 Draws shape at column 50, row 100.
68 FOR 2 • 1 TO 5 8 8 : HEXT 2
Stalls for a short time.
78 X D R A W 1 AT 5 8 , 1 8 8 Erases the shape.
The ROT= (for rotation) statement sets the angular rotation for the
high-resolution graphics shape to be drawn by DRAW or XDRAW. The
expression following the keyword ROT= specifies the rotation in units of
5.625 degrees (1/64 of a circle). ROT= 0 orients the shape exactly as
defined in the shape table, ROT= 16 rotates the shape 90 degrees clockwise,
ROT= 32 rotates it 180 degrees, and so on. The process repeats starting at
ROT= 64.
X d m
"'
✓
-
�
A B C D E F G
..
+l I
•
� ••• 1' �
- L ➔u
J K L M N 0
+t
-- � II
a
- ., ...
s w
-
R T V
C ::a
X y z
I ♦ \
I .I L
�
A
•
•
• 0�
�'(
..
•
•
•
•
•
•
•
•
161
The features covered in this chapter are concerned with low-level control of
the programming environment.
□ Section 7.1, "System Utilities," discusses facilities for direct access to
specific locations in the computer's memory from within an Applesoft
program.
□ Section 7 .2, "Memory Management," describes the ways in which
Applesoft programs can control the limits of program space.
□ Section 7 .3, "Debugging," tells how to trace the execution of a running
program for debugging purposes.
7. 1 System Utilities
�Warning Be certain that the address in which you are storing doesn't contain part
of your program or some vital system information that you don't want to
change. An ill-advised POKE can hang the system, drop you into the
Monitor, or alter the operation of the system or of your program in
unpredictable and possibly disastrous ways. In the event of catastrophe,
use I CONTROL H R ESET I to regain control of the system. See Appendix H
for the locations of vital system pointers that shouldn't be tampered with.
CALL 5 49 1 5
C A L L - 936
C A L L R O UT I N E C J )
The CALL statement executes a machine-language subroutine from within
an Applesoft program. The decimal address of the desired subroutine
follows the keyword CALL. Control is transferred to the subroutine at the
designated address; when the subroutine is finished, execution continues
with the statement following the CALL. For example,
C A L L 6 4 668
executes the machine-language subroutine beginning at address 64668.
A Warning Make sure the address you give in the CALL statement is the beginning of
a valid machine-language subroutine! A misdirected CALL can have
unpredictable and probably unpleasant consequences, such as hanging
the system or dropping you into the Monitor. If this happens to you, use
I CONTROL H RESET I to regain control of the system.
The Apple II's built-in firmware contains a number of useful subroutines
accessible with the CALL statement. See Appendix F for details.
·�
l P R I NT U S R ( 3 )
floating-point accumulator by 8.
Returns to Applesoft.
Executes routine with argument
value 3.
2◄ Result displayed on screen.
At hexadecimal address $0A, there is a JMP (opdcode 4C) to hexadecimal
address $300. (As usual in 6502 machine language, the low-order byte of the
address, 00, precedes the high-order byte, 03.) Beginning at address $300 is
a machine-language routine to multiply the value in the floating-point
accumulator by 8. Back in Applesoft, when the function call USR (3) is
executed, the argument value 3 is placed in the floating-point accumulator
and control is passed to the machine-language routine via the JMP at
location $0A. The machine-language routine gets the value in the
floating-point accumulator, multiplies it by 8, puts the result (24) back into
the floating-point accumulator, and returns control to Applesoft with an
RTS instruction (opcode 60). The value 24 is then passed back as the result
of the USR call.
To obtain a two-byte integer from the value in the floating-point
accumulator, your machine-language routine should do a JSR to
address $E01C. Upon return, the integer value is in locations $AO
(high-order byte) and $Al (low-order byte).
To convert an integer result to its floating-point equivalent, so that the
function can return that value, place the two-byte integer in registers A
(high-order byte) and Y (low-order byte). Then do a JSR to address $E2F2.
Upon return, the floating-point value is in the floating-point accumulator.
L O M E M : 2 4 5 76
The LOMEM: statement sets the lowest memory address available to an
Applesoft program for storage of variables. The lower limit of available
program memory is set to the value of the expression following the keyword
LOMEM:. The area below this address is available for high-resolution
graphics or machine-language programs. LOMEM: also resets all variables to
their initial values and wipes out all functions defined with DEF FN (see
Section 2.4.3).
Notice that the colon is part of the keyword LOMEM: and is required.
Applesoft ordinarily begins to store variables at the end of the program in
memory. Each time you add, delete, or change a program line, Applesoft
resets LOMEM: to a location just above the final line of the program.
Executing the NEW command (see Section 1.2.1) or typing �
to the Monitor resets LOMEM: to its initial value.
The value of LOMEM: can only be increased from its current setting. An
attempt to set LOMEM: to a lower value than the one already in effect halts
the program with the message ? O UT O F M E M O R Y E R R O R .
�Warning Changing LOMEM: during the course of a program is a most dangerous
practice that can cause portions of the program or of Applesoft's internal
control information to become unavailable, which in tum causes the
program to act in outlandish ways (if at all).
Helpful Hint: The current value of LOMEM: is stored in decimal
memory locations 105 and 106; to obtain that value, use the expression
PEEK C 1 06) * 256 + P E E K ( 1 0 5 )
If LOMEM: is given a negative address, it adds 65536 (2 to the 16th power)
to obtain an equivalent positive address. For example,
This Is Equivalent To
L OM E M : - 4 9 1 5 2 L O M E M : 1 6384
If the specified address is not in the range -65535 to +65535, the program
halts with the message ? I L L E G A L Q U A N T I TV E R R O R .
If the specified address is higher than the current setting of HIMEM:, or
lower than the address of the highest memory location occupied by the
current operating system (plus any currently stored program), the program
halts with the message ? O U T O F M E M O R Y E R R O R .
The FRE function yields the number of bytes of unused writable (RAM)
memory available to the running program. For example,
L E T AVA I L • F R E C B )
sets AVAIL to the amount of available memory remaining.
Notice that the name of the function is FRE, not FREE.
FRE requires an argument in parentheses. The argument given to FRE is
ignored, and has no effect on the operation of the function. However, you
can't leave it out-you must include an argument expression of some kind
to "keep the parentheses apart." What you use for an argument expression
doesn't matter, but if Applesoft can't evaluate it as a legal expression, you
get an error halt.
If the number of free bytes exceeds 32767, FRE yields a negative result;
adding 65536 gives you the actual number of free bytes:
I F F R E C B > < B T H E N A VA I L • F R E C B > + 6 5 5 3 6
If you have set HIMEM: beyond the highest RAM address in your Apple II,
FRE may yield a value higher than the computer's actual memory capacity.
The reliability of such a value is to be taken lightly.
How Applesoft Manages Free Space: The amount of free space
reported by FRE is the number of bytes remaining below the string
storage space and above the numeric array and string pointer array space
(see Section H.2). When Applesoft changes the contents of a string
variable during the course of a program (say from "CAT" to "DOG"), the
characters in the old string ("CAT") are not erased from memory;
Applesoft simply allocates some fresh space to hold the new string
("DOG"). As a result, characters left over from unused strings take up
"dead space" and slowly fill memory from HIMEM: down to the top of the
array space.
Applesoft automatically clears out these leftover characters when the
bottom of string space "collides" with the top of array space. But if you're
using any of the free space for machine-language programs or for
high-resolution graphics, they may be overwritten.
7 .3 Debugging Facilities
This section details two Applesoft commands used as debugging aids:
TRACE and NOTRACE. They're useful when a program isn't behaving as
intended and you need to find out why.
TRACE
TRACE causes Applesoft to display the line number o f each statement it
executes. Each line number displayed is preceded on the screen by a
number sign (#). For example, the program
1 111 TRACE
2 1! I • I + 1 I • I + 1
3 1! J • J + 1 J • J + 1
4 1! GOTO 2 1!
displays the output
# 2 1! # 2 1! # 3 1! # 3 1! # 4 1! # 2 1! # 2 1! # 3 1! # 3 1! # 4 1!
# 2 1! # 2 1! # 3 1! # 3 1! # 4 1! # 2 1! # 2 1! # 3 1! # 3 1! # 4 1!
# 2 1! #20 # 3 1! # 3 1! # 4 1! # 2 1! # 2 1! # 3 1! # 3 1! # 4 1!
# 2 1! # 2 1! # 3 1! # 3 1! # 4 1! # 2 1! # 2 1! # 3 1! # 3 1! # 4 1!
# 2 1! # 2 1! # 3 1! # 3 1! # 4 1! # 2 1! # 2 1! # 3 1! # 3 1! # 4 1!
175
Good programs don't just happen. Programs that are efficient, economical,
and easy to debug and to modify are the result of careful planning. This
chapter presents a method to facilitate such planning, using as its example
a program to calculate postage fees for United States mail. A copy of this
program is included on the ProDOS BASIC Programming Examples disk;
a complete listing can be found in Appendix N.
□ Section 8.1, "Planning the Program," shows how to develop a list of
program specifications and how to convert the list into a kind of program
outline.
□ Section 8.2, "Writing the Code," shows how to refine the outline
developed in Section 8.1 into a final Applesoft program.
Although you can afford to be "quick and dirty" for casual or one-time-only
applications, you'll need to do some preliminary planning for more serious
ones. In general, the more planning you do the more efficient and bug-free
your finished program will be.
To demonstrate some of the principles of program planning, this chapter
develops a program to calculate postage rates on certain classes of mail sent
in the United States.
Before rushing to put fingers to keyboard, it's best to take your planning at
least one step further. Now is the time for program layout. Here you plan
the form for each section of the program as described in both the
specification list and the chronological order list.
The program layout technique presented here is called stepwise
refinement.-Jl,lhat this means is laying out broad sections of the program,
then going back and refining each section step by step.
Your program should begin with a block of REM statements identifying the
program and describing what it does. Most programmers add their own
name and the date of the program's current version:
1 0 R E M P O STAGE R A T E S Name of program.
20 Colon leaves line empty.
3 0 R E M D E T E R M I N E S P O ST A G E F E E S
What program does.
4 0 R E M F O R E X P R E S S , 1 ST C L A S S ,
5 0 R E M A N D P R I O R I TY M A I L Empty line inserted by embedding
I CONTROL Kl] (line feed) at end of
REM statement in line 50.
6 0 R E M V 3 1 0 / 0 5 /83 Number and date of this version.
7 0 R E M B Y J O H N S C R I BBL E M O H G E R & S C OT K AM I H S
Programmers' credit line.
Now you can refer to your outline and base your code directly on it. Notice
the REM statements introducing the different sections. All comments
shown in the second column could also be included as REM statements:
1 0 0 R E M M E N U O F P O STAGE C L A S S E S
j c o NTR oL Hl] here.
'""-=--,,=-=-,.....,
This section finds out what mail class the user wants. Note that
I CONTROL 1-Q], the line feed character, sets off the REM statements for
easier reading (line 300):
3 8'1 R E M I CONTROL 1-Q] here.
G E T C L A S S OF MA I L I CONTROL 1-QJ here.
3 1 0 VTAB 1 4
3 2 0 P R I N T " P r e !!l !!I t h e n u m b e r o f y o u r c h o i c e : ., ;
Semicolon keeps response on same
line.
330 GET C $ Only one keypress needed-cuts
down on error possibilities; note use
of string variable to get number
avoids type mismatch errors.
335 REM I CONTROL f-Q] here.
V A R I □us C H E C K S Another j CONTROL f{I) (last time
this is noted).
340 I F C $ • "4" THEH EHD Ends program if user types a 4 .
350 I F VAL C C $ ) > 0 AHO VAL C C $ ) < 4
THEH 380 Skips next two lines if valid choice
typed.
360 PR I HT CHR $ C 7 > ; CHRH 7> ; Beeps twice to get attention.
3 7 0 G O T □ 33 0 Response was invalid; tries again.
3 0 0 P R I HT C $ Since choice accepted via GET, it
isn't displayed on the screen;
displays it back to user.
390 C • VAL C C U Needs this value later to determine
what section of program to branch
to for proper processing.
Now the program asks the user for the weight of the letter or package. The
program makes sure that the user follows the instructions and types a
number for the weight and a symbol (0 or P) for ounces or pounds. Notice
that the program accepts both the numeric weight of the item and the
ounce/pound designation in the same string (line 530).
S ell R E M
G E T W E I G H T O F I TE M
5 1 5 VTAB 16
5 1 0 P R I H T " P l e a 5 e e n t e r t h e WE I GHT - a n u mb e r p l u 5
an O ( fo r ounc e 5 ) or a P ( fo r pound 5 ) - and
p r e 5 5 t h e R E T U R H k ey : " ;
Prompting message to tell user what
information to type and how to type
it.
5 2 0 C A L L - 868 Clears to end of line; useful to erase
any errors that might be typed.
530 I H P U T " " ; W $ Empty string suppresses question
mark.
5 4 0 W 1 $ • R I GH T $ C W $ , 1 ) Rightmost letter should be either 0
or P; use it later to see if weight is
consistent with postal regulations.
5 5 0 W • VAL CW$ ) How many ounces or pounds?
555 REM
W A S E H T E R E D W E I GH T V A L I D ?
560 I F W > 0 AHD ( W 1 $ • "0" OR W 1 $ • " P " ) THEH 7 1 0
If a weight was typed, and if last
character was either O for ounces
or P for pounds, then proceeds.
570 P R I HT CHR S ( 7 ) ; CHRS ( 7 ) ;
Beeps twice to get attention.
If the program has progressed this far, then everything typed by the user is
valid from the computer's point of view. However, the user's choices still
may not be consistent with postal regulations or the program's limitations.
First class letters must weigh less than 12 ounces, the program can't handle
express mail above a certain weight, and so on. This section of code uses
the value of variable C (set in line 390) to direct control to the proper
subroutine to check for consistency.
After the postage charge is calculated, the program branches to this final
subroutine. Here the final result is checked to see how it will look when it is
displayed. Does it have a decimal point? Applesoft suppresses trailing zeros
after a decimal point, but people are used to seeing them when dealing with
dollars and cents. The formatting subroutine adds trailing zeros as needed.
6 1 0 0 0 REM
MON E Y F O RMATT E R Adds zeros after the decimal point
where needed.
61 0 1 0 T S • STR S C T > Turns the calculated postage fee
into a string.
61 020 I F T • I NT C T > T H E N T S • T S + " , 0 0 "
If charge is in whole dollars, adds a
decimal point and two zeros.
6 1 030 I F A S C < R I GH T S C T S , 2 » • 46 T H E N T S • T S + " 0 "
If second character from the right is
a decimal point (ASCII code 46)
then number has only one digit to
right of decimal-so adds a "O" to
the string.
61 040 RETURN Ends the routine.
..
•
•
195
This appendix lists abbreviated descriptions of all Applesoft statements and
functions. Each description is preceded by a syntactic definition and at least
one example; see Appendix B for definitions of syntactic terms used here.
References in square brackets at the end of each description give the
section or appendix of this manual where more detailed information about
the feature can be found.
-
ABS
-
ASC
Assignment Statement
-
ATN
-
CHR$
Syntax: C H R $ c aexpr>
Example: CHR$ (65)
Yields the character corresponding to the ASCII code given as an argument.
The example yields the letter A. [4.2.5.3]
CLEAR
Syntax: CLEAR
Example: CLEAR
Resets all variables and internal control information to their initial state.
Program code is unaffected. [1.2.2]
COLOR =
Syntax: C O L O R • aexpr
Example: COLOR• 1 2
Sets the display color for plotting low-resolution graphics. The example sets
the display color to green. [6.1.2]
-
CONT
Syntax: c□HT
Example: CONT
Resumes program execution after it has been halted by STOP, END,
� or (sometimes) I CONTROL H RESET j. [l.3.3]
-
DAT�
DEF FN
-
DEL
DRAW
-
END
Syntax: EHD
Example: EHD
Terminates the execution of the program and returns control to the user. No
message is displayed. [3.6.2]
-
EXP
Syntax: E X P c aexpr>
Example: EXP C2>
Yields the mathematical exponential of its argument (the constant
e = 2. 7182818 raised to the power specified by the argument). The example
yields e squared, or 7.3890561. [2.4.1.9)
Syntax: FLASH
Example: FLASH
Causes all text displayed on the screen with subsequent PRINT statements
t,o flash between white-on-black and black-on-white. May not work properly
for lowercase letters (and other characters with ASCII codes above 95) if
the 80-Column Text Card is installed and running in "active-80" mode.
[5.2.4.10]
-
FN
Syntax: F N name < aexpr>
Example: F N C U BE ( 6 )
-
FOR
-
GET
Syntax: G E T var
Example: GET A N SWE R $
GOSUB
Syntax: G O S U B linenum
Example: G O S U B 2 5 ll
GOTO
Syntax: G O T O linenum
Example: G O T O 4 ll ll
Syntax: GR
Example: GR
Converts the display to 40 rows of low-resolution graphics with four lines of
text at the bottom. The screen is cleared to black, the cursor is moved to the
beginning of the last line, and the low-resolution display color is set to black.
[6.1.l]
HCOLOR =
Sets the display color for plotting high-resolution graphics. The example
sets the display color to green. [6.2.3]
-
HGR
Syntax: HGR
Example: HGR
Converts the display to 160 rows of high-resolution graphics with four lines
for text at the bottom. The screen is cleared to black and page 1 of
high-resolution graphics is displayed. The contents of the text display, the
location of the cursor, and the high-resolution display color are unaffected.
[6.2.1]
-
HGR2
Syntax: HGR2
Example: HGR2
Sets the address of the highest memory location available to the Applesoft
program, including its variables. The example sets the end of program and
variable storage to 32767. Used to protect an area of memory for data,
high-resolution graphics, or machine-language code. [7.2.1]
-
HLIN
HOME
Syntax: HOME
Example: HOME
Clears all text from the text window and moves the cursor to the top-left
comer of the window. [5.2.4.3]
HPLOT
Syntax: H P L O T aexpr, aexpr [ { ro aexpr , aexpr} ]
H P L O T TO aexpr, aexpr [ { ro aexpr , aexpr} ]
Examples: HPLOT 75 , 2 0
H P L O T 4 8 , 1 1 5 T O 79 , 8 4 T O 1 1 0 ,
1 1S
HPLOT TO 2 7 0 , 1 0
Syntax: H T A B aexpr
Example: HTAB 2 3
Positions the cursor to a specified column of the text display. The example
moves the cursor to column 23. If you have the Apple II 80-Column Text
Card, see the manual accompanying that product for further information on
using HTAB. [5.2.4.6]
IF ...THEN
Specifies the source for subsequent input. The example causes subsequent
input to be read from the device at port 2. [5.1.1]
iNPUT
-
I NT
Syntax: I NT caexpr>
Examples: I NT ( 98 . 6 )
I NT C - 2 7 3 , 1 6 )
Yields the integer part of the argument value. The examples yield 98
and -274, respectively. [2.4.1.3]
INVERSE
Syntax: I NV E R S E
Example: I NV E R S E
Causes all text displayed on the screen with subsequent PRINT statements
to appear in black-on-white instead of the usual white-on-black. May not
work properly for lowercase letters (and other characters with ASCII codes
above 95) if the 80-Column Text Card is installed and running in "active-80"
mode. [5.2.4.9]
-
LEN
Syntax: L E H c sexpr>
Example: L E H < "NEVE R A DULL MOME NT" )
Yields the length of a string in characters. The example yields 19. [4.2.2]
-
LET
See "Assignment Statement."
-
LIST
Displays all or part of the program on the screen, or writes it to the current
output device. The first example lists the entire program; the second lists
line 150 only; the last two list lines 200 to 300, inclusive. [1.2.3]
Syntax: L O A D [name]
Examples: LOAD
L O A D DEMO
Reads a program into memory from a disk or tape. The first example reads a
program from a tape cassette; the second reads from a disk file named
DEMO (casette tape cannot be used with Apple Ile). If you have one or more
disk drives, see your disk operating system manual for further information.
[1.2.6, M]
-
LOG
LOMEM:
Syntax: L OM E M : aexpr
Example: L O M E M : 2 4 5 76
Sets the address of the lowest memory location available to the program for
variable storage. The example sets the beginning of variable storage
to 24576. [7.2.2]
·
-
MID$
-
NEXT
Syntax: N E X T [ avar [ { , avar} ] ]
Examples: NEXT
N E X T I NDE X
NEXT J , I
Marks the end of a loop and causes the loop to be repeat.ed for the next
value of the index variable, as specified in the corresponding FOR
stat.ement. The first example ends the most recently ent.ered loop; the
second ends the loop whose index variable is INDEX; the third ends the pair
of nest.ed loops whose index variables are J and I. [3.3.2]
NORMAL
Syntax: N O RM A L
Example: N O RM A L
Causes all t.ext displayed on the screen with subsequent PRINT stat.ements
to appear in the usual white-on-black; cancels the effects of INVERSE or
FLASH. [5.2.4.11]
NOTRACE
Syntax: HOTRACE
Example: NOTRACE
Stops the display of line numbers for each stat.ement execut.ed; cancels the
effects of TRACE. [7.3.2]
ON ... GOTO
ONERR GOTO
-
POL
Syntax: PDL c aexpr>
Example: PDL C 1 >
Reads the current dial setting on a designated hand control. The example
reads the dial on hand control 1. [5.1.6.1, F.4]
-
PLOT
Syntax: P L O T aexpr , aexpr
Example: P L O T 1fil , 2 0
Plots a single block of the current display color at a specified position on the
low-resolution graphics screen. The example plots a block at column 10,
row 20. [6.1.3]
-
POKE
Syntax: P o K E aexpr , aexpr
Example: P O K E - 1 63 0 2 , 0
Stores a value in a specified location in memory. The example stores the
value O at location 49234 (65536 - 16302), causing the display to switch from
mixed graphics and text to full-screen graphics. [7.1.2, F]
-
POP
Syntax: POP
Example: POP
Removes the most recent return address from the control stack, causing the
next RETURN statement to send control to the statement following the
second most recently executed GOSUB. [3.4.4]
-
PR#
Syntax: P R I aexpr
Example: PR# 1
Specifies the destination for subsequent output. The example causes
subsequent output to be sent to the device at port 1. [5.2.1]
Syntax: P R I H T [ { expr [ , I ; ] } ]
Examples: P R I NT
P � I HT A $ , " X • " ; X
Writes a line of output to the current output device. The first example
writes a blank line; the second writes the value of variable A$, followed at
the next available tab position by the string "X = ", followed immediately
by the value of variable X. (5.2.2]
-
READ
-
REM
Syntax: R E M {character}
Example: R E M TH I s A R E M A R K
RESTORE
Syntax: R E ST O R E
Example: R E ST O R E
Causes the next READ statement executed to beginning reading at the first
item of the first DATA statement in the program. [5.1.5]
RESUME
Syntax: R E S UME
Example: R E S UME
RETURN
Syntax: RETURN
Example: RETURN
The last statement in a subroutine returns control from a subroutine to the
statement following the GOSUB that called the subroutine. [3.4.2]
-
RND
Syntax: R H O c aexpr>
Example: RHO ( 1 )
Yields a random number between O and 1. Zero and negative argument
values yield repeatable sequences of random numbers. [2.4.2]
ROT =
Syntax: R O T • aexpr
Example: ROT• 1 6
Sets the angular rotation for high-resolution shapes to be drawn with DRAW
or XDRAW. The example causes the shape to be rotated 90 degrees
clockwise. [6.3.2.4]
-
RUN
SCALE =
Syntax: S C A L E • aexpr
Example: S C A L E • 1 111
Sets the scale factor for high-resolution shapes to be drawn with DRAW or
XDRAW. The example causes the shape to be drawn ten times bigger than
the definition given in the shape table. [6.3.2.3]
-
SCRN
Syntax: s c R Ii < aexpr , aexpr>
Example: S C R N ( 1111 , 2 111 >
Yields the code for the color currently displayed at a designated position on
the low-resolution graphics screen. The example yields the code for the
color at column 10, row 20. [6.1.6]
-
SGN
Syntax: S G N caexpr>
Example: SGN C - 1 4 4 )
II, II Plus, lie I Loads a shape table into memory from a tape cassette. [6.3.2.5, M]
-
SIN
Syntax: S I M caexpr>
Example: SIM <2>
Yields the sine of the argument, which must be expressed in radians. The
example yields .909297427. [2.4.1.5)
-
SPC
Syntax: sPc caexpr>
Example: SPC (8)
Introduces a specified number of spaces into the line being written by a
PRINT statement. The example writes eight spaces. [5.2.4.4)
SPEED =
Syntax: S P E E D • aexpr
Example: S P E E D • S il
Sets the rate at which text characters are to be sent to the display screen or
other input/output device. The slowest rate is O; the fastest is 255.
[5.2.4.12]
-
SQR
Syntax: S Q R caexpr>
Example: SQ R C 2 >
Yields the positive square root of the argument; the example yields
1.41421356. [2.4.1.4]
Terminates the execution of the program and returns control to the user. A
message is displayed identifying the program line in which the STOP
statement appears. (3.6.1]
STORE
Syntax: STORE name[x]
Example: STORE MX
I I , II Plus, lie I Stores values from an array onto a tape cassette. The example stores the
contents of array MX. [M]
-
STR$
Syntax: STR S caexpr>
Example: STR S < 1 2 . 4 5 )
Yields a string representing the numeric value of the argument. The
example yields the string "12.45". [4.2.5.1, I]
-
TAB
Positions the text cursor at a specified position on the output line during
execution of a PRINT statement. The example moves the cursor to
column 23. [5.2.4.5]
-
TEXT
Syntax: TEXT
Example: TE X T
Converts the display to 24 lines of text, with the cursor positioned at the
beginning of the bottom line. [5.2.4]
TRACE
Syntax: TRACE
Example: TRACE
Causes the line number of each statement to be displayed on the screen as
it is executed. [7.3.1]
-
USR
Syntax: V A L c sexpr>
Example: VAL C " - 3 . 7E4")
-
VLIN
-
VTAB
-
WAIT
221
This appendix describes the syntax definitions given in Appendix A. The
following symbols are used in the syntax definitions:
means "is defined as"
separates alternative definitions (alternative definitions for the same
term may also be given separately)
[] enclose elements that can be omitted
{ } enclose elements that can be repeated one or more times
aexpr (arithmetic expression)
real I integer I avar I fcall
unop aexpr
aexpr alop aexpr
sexpr relop sexpr
(aexpr)
Parentheses cannot be nested more than 36 levels deep.
alop (arithmetic or logical operator)
aop l relop I lop
aop (arithmetic operator)
+ 1-1*1/I
avar (arithmetic variable)
realvar I intvar
character
letter I digit I spchar I quote I space
digit
0111213141516171819
expr (expression)
aexpr I sexpr
fcall (function call)
name ( expr [ {, expr} ] )
integer
[ + I - ] {digit}
Integers must be between -32767 and +32767 to be valid.
real
[+ I -] {digit} [ . {digit} ] [ E [+ I -] [ digit [digit] ] ]
[+ I -] [ {digit} ] . [ {digit} ] [ E [+ I -] [ digit [digit] ] ]
The letter E in a real number stands for "times 10 raised t.o the power after
the E." Valid reals must be between -1E38 and + 1E38.
•
•
,o
•
•
227
This appendix contains a chart of the ASCII (American Standard Code for
Information Interchange) character codes. The first 32 codes represent
control characters; to type these characters from the Apple computer
keyboard, press I CONTROL I and hold it down while pressing the designated
character. (Some of these characters also have single-key representations,
as noted.) The abbreviations given for these codes in the column labeled
Char represent standard control functions originally intended for use on
teletypes; the meanings of these abbreviations are given in the Meaning
column. Functions marked with a dagger (t) are implemented on the
Apple iI; the others are listed purely for historical interest.
I Note: Older model Apples (II, II Plus) don't have some of the keys listed
in the Type column. To access these characters, use the CHR$ function.
Dec = decimal ASCII code
Hex = hexadecimal ASCII code
Char = ASCII character name
Type = what you type from the Apple computer keyboard
63 3F ? 95 5F 127 7F I DELETE I
231
Table D-1 lists Applesoft's reserved words. In most cases these character
sequences cannot be used as, or embedded in, variable names.
Applesoft converts all its keywords to one-byte codes, called tokens, to
save memory. Refer to Section H.4 for a list of tokens. All other characters
in a program occupy one byte each of program storage.
The ampersand character (&) is reserved for Applesoft's internal use and
for user-supplied machine-language routines. When executed as an
instruction, it causes a JSR to address $03F5 hexadecimal.
XPLOT is a reserved word that does not correspond to a current Applesoft
statement.
Some reserved words are recognized by Applesoft only in certain contexts:
□ COWR, HCOLOR, ROT, SCALE, and SPEED are interpreted as reserved
words only if the next nonspace character is an equal sign ( = ). This is of
little benefit in the case of COLOR and HCOLOR, as the embedded
reserved word OR prevents their use as variable names anyway.
□ HIMEM and LOMEM are interpreted as reserved words only if the next
nonspace character is a colon (:).
□ IN and PR are interpreted as reserved words only if the next nonspace
character is a number sign ( #).
□ SCRN, SPC, and TAB are interpreted as reserved words only if the next
nonspace character is a left parenthesis, (.
□ ATN is interpreted as a reserved word only if there is no space between
the T and the N. If a space occurs between the T and the N, the reserved
word AT is interpreted instead of ATN.
□ TO is interpreted as a reserved word unless it is preceded by an A and
there is a space between the T and the 0. In that case, the reserved word
AT is interpreted instead of TO.
Even if you don't embed reserved words in your variable names, they can
sometimes pop up unexpectedly and cause problems. For example, the
statement
1ee F O R A • L O F T O R L E F T TO 1 5
is interpreted as
1ee F O R A • LOF TO R L E F T TO 1 5
and causes a syntax error. To force the correct interpretation, use
parentheses:
1ee F O R A • ( L O F T ) OR C L E F T ) TO 1 5
e
•
•
•
235
This appendix lists Applesoft's error messages and their causes. When an
error occurs in immediate execution, Applesoft sounds a beep and displays
a message of the form
?XX ERROR
where x x is the name of the particular error.
In deferred execution (during the course of a running program), the
message takes the form
? X X ERROR I H VY
where v v is the line number of the statement in which the error occurred,
the Applesoft prompt character ( ] ) and the cursor are displayed, and control
of the system is retumed t,o the user. Variable values and the text of the
program remain intact, but internal control information is erased and the
program cannot be continued with the CONT command (refer t,o
Section 1.3.3). An error in a deferred-execution statement is not detected
until the statement is executed.
The error handling described can be overridden by an error-handling
routine in the program itself, established with the ONERR GOTO statement
(refer t,o Section 3.5.1). Error codes for use in such an error-handling routine
are shown in square brackets following the error names. When an error
occurs, the code listed is soored at location 222 decimal; it can be retrieved
from that location with the PEEK function (refer t,o Section 7.1.1). Errors for
which no code is given cannot occur in deferred execution.
Errors associated with the disk operating system also register at
location 222; see the disk operating system manual for further information.
Debugging suggestions given under the individual error messages are not
intended t,o be exhaustive or comprehensive; the causes of program bugs
are as numberless as the sands of the sea and stars of the sky.
ILLEGAL DIRECT
An attempt was made to use one of the following statements in immediate
execution:
□ DEF FN
□ GET
□ INPUT
□ ONERR GOTO
□ READ
□ RESUME
□ use of LEFT$, MID$, RIGHT$, WAIT, PEEK, POKE, CALL, TAB, SPC,
ON...GOTO, ON...GOSUB, or any of the graphics statements or functions
with an improper argument.
OVERFLOW [69)
The result of an arithmetic calculation was too large to be represented in
Applesoft's internal number format.
SYNTAX ERROR ( 1 6]
A reference was made to a function that had never been defined. Can occur
when you type something like F H L c x > when you meant to type
r H I c x > ; that is, a simple case of mistaken identifier.
An attempt was made to transfer control, via GOTO, GOSUB, or IF ... THEN,
to a nonexistent line number. Common causes include accidentally deleting
a line, changing a line number without changing references from other lines
accordingly, and simple typing errors.
•
•
•
•
•
•
•
•
243
This appendix discusses some of the many special features of the Apple II
that you can use in your Applesoft programs by means of PEEK, POKE, or
CALL statements (see Sections 7.1.1, 7.1.2, and 7.1.3, respectively). Notice
that some of them duplicate the effects of other Applesoft features.
Many of these special addresses are soft switches-specific locations in
memory that produce some special effect whenever the contents are read or
written-any reference to them, whether a read (that is, a PEEK) or a write
(a POKE), invokes the feature associated with the address. For instance, the
sample given here for switching from text to graphics without clearing the
graphics screen is
P O K E - 1 63 0 4 , 0
but you can get the same effect by executing
X • P E E K C - 1 63 0 4 )
or by using POKE to address -16304 with a value other than 0. This does not
apply in cases where you must use POKE to store a specific value into the
special address, such as a margin setting or a cursor location.
For More Information: For more information on special features
accessible with PEEK, POKE, and CALL, see your Apple's reference
manual.
F. 1 Screen Text
The special locations described in this section are used for controlling the
display of text on the screen:
o setting the boundaries of the text window within which characters are
displayed and scrolled
o clearing all text from all or part of the screen
o scrolling text within the text window
o controlling the position of the cursor.
Setting the text window does not clear the remainder of the screen (for
which you can use HOME) and does not move the cursor into the new text
window (use HOME again, or HTAB and VTAB-see Section 5.2.4).
3 il I NP U T I I I L E F T : I I ; L
4 il I NP UT I I I W I DTH : II ; w
S il I N P U T I I I TOP : II ; T
S il I N P U T II I BOTTOM : II ; B
7 il POKE 33 , W
S il P OK E 3 2 , L
S il POKE 34 , T
1 B il POKE 35 , B
1 1 " GOTO 1 B
POKE 32 L
Sets the left edge of the text window to the value specified by expression L.
This value should be between 0 and 39 (or 0 and 79 if you're using
80 columns), where 0 represents the leftmost column of the screen.
The change doesn't become visible until the cursor attempts to return to the
left edge of the window.
•Warning The width of the window is not changed by this statement: this means
that the right edge is moved by the same amount you move the left edge.
To protect your program and Applesoft, first reduce the window width
appropriately; then change the left edge.
POKE 33 W
Sets the width of the text window (number of characters per line) to the
value specified by expression W. This value should be between 1 and 40
(or 1 and 80 if you're using 80 columns).
POKE 34 T
Sets the top edge of the text window to the value specified by expression T.
This value should be between 0 and 23, where 0 represents the top line of
the screen.
AWarning I Do not set the top edge of the window (T) lower than the bottom edge.
POKE 35 B
Sets the bottom edge of the text window to the value specified by
expression B. This value should be between 0 and 23, where 23 represents
the bottom line of the screen.
By the Way: No matter what you do to the left margin, width, top, and
bottom of the text window, you can quickly restore it to the full screen
with the TEXT statement.
AWarning Make sure the bottom of the text window doesn't extend past the bottom
of the display screen. Setting the window bottom beyond line 23 causes
display text to be written outside the usual memory area reserved for it,
destroying parts of your program or vital system information.
Do not set the bottom edge of the window (B) higher than the top edge.
CALL -936
Clears all text within the text window and moves the cursor to the top-left
corner of the window. The effect is the same as that of the HOME statement
or of press� I Esc I [ru from the keyboard.
CALL -958
Clears all characters inside the text window from the current cursor
position to the bottom-right corner. Characters above and to the left of the
cursor are not affected. The effect is the same as that of pressing I Es c 1 1 I:]
from the keyboard.
CALL -868
Clears all characters inside the text window from the current cursor
position to the end of the line. The effect is the same as that of pressing
I ESC I (I) from the keyboard.
CALL -922
Issues a line feed character, causing the cursor to move down one line
without changing its horizontal position. If the cursor is on the bottom line
of the text window, the contents of the window are scrolled up one line. The
effect is the same as that of pressing I CONTROL HI] from the keyboard.
CALL -9 1 2
Scrolls all text within the text window up one line. The old top line is lost;
the old second line becomes the top line; the bottom line becomes blank.
Text outside the text window is not affected.
PEEK (36)
Yields the current horizontal position of the cursor, a number between 0
and 39 (0 and 79, if you're using 80 columns). The cursor position is given
relative to the left edge of the text window, not the left edge of the screen.
The effect is the same as that of the POS function (see Section 5.2.4).
POKE 36, CH
Moves the cursor to the horizontal position specified by expression CH,
which is interpreted relative to the left edge of the text window, not the left
edge of the screen. The value of this expression should be between O and
the current width of the window, with O representing the leftmost column
of the window. The effect is the same as that of the HTAB statement (see
Section 5.2.4.6), but is not limited to 40 columns.
Like HTAB, this statement can move the cursor beyond the right edge of the
text window, but only long enough to display one character.
80-Column Users: You can use this POKE statement to position the
cursor in columns 40 to 79 of the screen, which are inaccessible with
HTAB.
•Warning Don't move the cursor past the right edge of the display screen! The
cursor position shouldn't be set greater than 40 (or 80) minus the current
left edge of the window. For example, if you've set the left edge of the
window to 10, don't set the cursor position greater than 30 (or 70 with
80 columns). Moving the cursor too far to the right may cause display text
to be written outside the usual memory area reserved for it, destroying
parts of your program or vital system information.
PEEK (37)
Yields the current vertical position of the cursor, a number between 0
and 23. The cursor position is given relative to the top edge of the screen,
not the top edge of the text window. A value of O represents the top line of
the screen, 23 the bottom line.
F.2 Keyboard
The following special locations are used for reading input directly from the
keyboard.
POKE - 1 6368, 0
Clears the high-order bit of location -16384 to prepare for reading another
keyboard character. This should be done immediately after reading the
keyboard via PEEK (-16384).
Four areas are reserved in the Apple H's memory for displaying text and
graphics on the screen:
□ Low-resolution page 1 is located at addresses $400 to $7FF hexadecimal
(1024 to 2047 decimal). Information stored in this area can be interpreted
and displayed on the screen in the form of either text or low-resolution
graphics. This is the usual area of memory used for both these purposes,
and is the area used by Applesoft's TEXT and GR statements.
□ Low-resolution page 2, at addresses $800 to $BFF hexadecimal (2048 to
3071 decimal), can be used as an alternate area for either text or
low-resolution graphics. Since this is the same area as the beginning of
Applesoft's normal program storage space (see Section H.l), using it for
text or graphics is tricky and is not recommended.
□ High-resolution page 1, at addresses $2000 to $3FFF hexadecimal
(8192 to 16383 decimal), is the usual area for high-resolution graphics,
and is accessible via Applesoft's HGR statement.
□ High-resolution page 2, at addresses $4000 to $5FFF hexadecimal
(16384 to 24575 decimal), serves as an alternate area for high-resolution
graphics, and is accessible via Applesoft's HGR2 statement.
To use the different text and graphics areas, you can use Applesoft's built-in
text and graphics facilities or you can use PEEK and POKE to manipulate
soft switch: a location in memory that the soft switches that control the display of text and graphics. There are
produces some special effect whenever its four such soft switches, each consisting of a pair of special locations in the
contents are read or written Apple II's memory. Any PEEK or POKE to one of the locations in the pair
sets the switch one way; a PEEK or POKE to the other location in the pair
sets the switch the other way.
In the following list, the addresses shown in parentheses are those of the
special locations that control the various settings of the switches. Each
address is given first in hexadecimal (preceded by a dollar sign, $) and then
in the equivalent decimal form.
The four soft switches controlling the display choose between
□ text ($C051, -16303) and graphics ($C050, -16304)
□ high ($C057, -16297) and low resolution ($C056, -16298)
□ page 1 ($C054, -16300) and page 2 ($C055, -16299)
□ full-screen graphics ($C052, -16302) and mixed text and graphics
($C053, -16301)
These POKEs let you switch from one text or graphics mode to another.
POKE -1 6304, 0
Switches the display from full-screen text to graphics without clearing the
graphics screen. Depending on the settings of the other soft switches, the
resulting display may be high- or low-resolution graphics, taken from page 1
or 2, and full-screen graphics or mixed text and graphics.
Similar Applesoft Statements: The GR statement switches to mixed
text and low-resolution graphics from page 1 and clears the graphics
screen to black. The HGR statement switches to mixed text and
high-resolution graphics from page 1 and clears the graphics screen to
black. The HGR2 statement switches to full-screen high-resolution
graphics from page 2 and clears the entire screen to black.
POKE -1 6303, 0
Switches the display from any fonn of graphics to full-screen text without
resetting the text window. Depending on the setting of the applicable soft
switch, the text displayed may be taken from low-resolution page 1 or
page 2.
The TEXT statement also switches to text display, but in addition selects
page 1, resets the text window to the full screen, and positions the cursor in
the bottom-left corner of the screen (column 1, row 24).
POKE - 1 6302, 0
Switches the display from mixed text and graphics to full-screen graphics.
Depending on the settings of the other soft switches, the resulting display
may be either low- or high-resolution graphics and may be taken from either
page 1 or page 2. If full-screen text is currently being displayed, there is no
visible effect.
POKE -1 6300, 0
Switches the display from page 2 to page 1, without clearing the screen or
moving the cursor. Depending on the settings of the other soft switches, the
resulting display may be text or low-resolution graphics taken from
low-resolution page.1, or high-resolution graphics taken from
high-resolution page 1; if graphics, it may be either full-screen graphics or
mixed with four lines of text from low-resolution page 1.
Always execute this POKE statement before switching to Integer BASIC if
you've been using page 2 in Applesoft; otherwise you'll be left still looking
at text Oow-resolution) page 2 while Integer BASIC is writing its screen
output to page 1.
POKE - 1 6299, 0
Switches the display from page 1 to page 2, without clearing the screen or
moving the cursor. Depending on the settings of the other soft switches, the
resulting display may be text or low-resolution graphics taken from
low-resolution page 2, or high-resolution graphics taken from
high-resolution page 2; if graphics, it may be either full-screen graphics or
mixed with four lines of text from low-resolution page 2.
POKE -1 6297, 0
Switches from low- ·to high-resolution graphics, without clearing the screen.
Depending on the settings of the other soft switches, the resulting display
may be taken from high-resolution page 1 or page 2, and may be either
full-screen high-resolution graphics or mixed with four lines of text from the
corresponding low-resolution page. If full-screen text is currently being
displayed, there is no visible effect.
CALL - 1 998
Clears low-resolution page 1 to black if displaying low-resolution graphics,
or to black-on-white at-signs (@) if displaying text. If displaying
high-resolution graphics, or text or low-resolution graphics from page 2,
there is no visible effect.
CALL - 1 994
Clears the upper 40 rows of low-resolution page 1 to black if displaying
low-resolution graphics, or the upper 20 lines to black-on-white at-signs (@)
if displaying text. If displaying high-resolution graphics, or text or
low-resolution graphics from page 2, there is no visible effect.
CALL -3082
Clears the current high-resolution page t,o the color most recently used in an
HPLOT statement. (Applesoft remembers which page you used last,
regardless of the switch settings.)
This section describes the special locations in the Apple II's memory for
controlling a variety of input and output devices:
□ reading the butrons on the hand controls
□ controlling the annunciaror outputs and the utility strobe
□ producing sounds through the built-in speaker.
F.4.2 Annunciators
These eight POKEs control the annunciator output on hand control
connectors.
Notfor Ile Users: The Apple lie doesn't have easily-accessible
annunciators. Apple lie users can safely dispense with reading the next
eight entries, but note that the locations discussed, POKE locations -16295
through -16290, are used by the system. They are generally not free
locations.
What's an Annunciator? The annunciators are four pins of the hand
control connector that can each be set to either of two states (on or off) in
the Apple II, Apple II Plus, and Apple lie. The utility strobe is another pin
of the connector that is normally at +5 volts but can be triggered to drop
to 0 volts for one-half microsecond. These features are typically used to
control devices such as lamps and relays connected to the computer
through the hand control connector. See your Apple's reference manual
for further information.
POKE -1 6295, 0
Turns on annunciator output 0 (hand control connector, pin 15).
POKE -1 6293, 0
Tums on annunciator output 1 (hand control connector, pin 14).
POKE -1 6294, 0
Tums off annunciator output 1 (hand control connector, pin 14).
POKE - 1 629 1 , 0
Tums on annunciator output 2 (hand control connector, pin 13).
POKE - 1 6292, 0
Tums off annunciator output 2 (hand control connector, pin 13).
POKE -1 6289, 0
Tums on annunciator output 3 (hand control connector, pin 12).
POKE -1 6290, 0
Tums off annunciator output 3 (hand control connector, pin 12).
F.4.3 Loudspeaker
These PEEKs produce audible clicks.
F .5 Error Handling
PEEK (21 6)
Yields a result > 127 if an error-handling routine has been established with
the ONERR GOTO statement, < = 127 if normal error handling is in effect.
POKE 2 1 6 0
Restores Applesoft's normal error-handling mechanism; cancels the effect
of a previous ONERR GOTO statement.
PEEK (222)
After an error-handling routine has been called, yields the error code
identifying the type of error detected. See Appendix E and Table 3-1
(Section 3.5.1) for further information on error codes.
Errors associated with the disk operating system also register at
location 222; see the disk operating system manual for further information.
CALL 549 1 5
Empties the internal control stack of all control information, without
affecting the contents of any variables.
..
259
The information in this appendix can help you write programs that run
faster or use less memory space.
□ Section G.l, "Saving Space," gives tips you can follow if you need to
conserve memory space.
□ Section G.2, "Saving Time," suggests ways to speed up program
execution.
G . 1 Saving Space
Serious programmers often keep two versions of their programs: one
expanded and heavily documented with REM statements, the other
"crunched" to use the minimum memory space. There are a number of
utility programs on the market that will make Applesoft programs more
compact. They work by automatically removing REM statements,
combining several statements onto a single program line, and eliminating
optional semicolons in PRINT lists. Here are some tips for programmers who
prefer to do the work themselves:
□ Use multiple statements per line. There is a small amount of overhead
(five bytes) associated with each line in the program. Two of these bytes
contain the line number. This means that no matter how many digits you
have in your line number (minimum line number is 0, maximum
is 63999), it takes the same number of bytes (two). Putting as many
statements as possible on each line cuts down on the number of bytes
used by your program. (A single line can include up to 239 characters.)
When combining statements into fewer lines, remember that when the
condition in an IF...THEN statement is false, execution continues with
the next line and not necessarily with the next statement.
If you're counting bytes, remember to add in one byte for each colon used
to separate statements.
The Disadvantages: Combining many statements on one line makes
editing and other changes much more difficult. It also makes a program
more difficult to read and understand, not only for others but also for you
yourself when you return to the program later on. Use this technique only
in programs with serious space limitations.
388 R E M TH I S I S THE H E X T R O UT I H E
and you delete line 300, the program halts with an U H D E F • D STATE M E H T
error.
The Di,sadvantages: Like programs with many statements on each line,
those without detailed REM statements are difficult to read and
understand, not only for others but also for you yourself when you return
to the program later on. You should consider eliminating REM statements
only when faced with a serious shortage of memory space.
o Use integer instead of real arrays wherever possible (see Section H.2).
o Use variables instead of constants. Suppose you use the constant 3.14159
ten times in your program. If you insert a statement
P I • 3 . 1 4 1 59
and then use the variable PI instead of the constant 3.14159 each time it
is needed, you save 40 bytes. This also results in a speed improvement.
o Applesoft programs need not end with an END statement, so you can
save a little space by omitting it.
o Reuse the same variables. If you use a variable T to hold a temporary
result in one part of the program and you need a temporary variable later
in your program, use T again. Or if you're accepting a one-character input
from the user in two different places in the program, use the same
variable both times.
◄ II L E T C • 1 11
S Ii P R I NT A $ B $ C $ " F R E D I s II
C II
HOURS
L A TE ! "
This program displays
W E L L , M A R S H A , I T L O O K S L I K E F R E D I S 1 11 H O U R S LATE !
But in this example several of the variables are run together and
interpreted as a single name:
1 11 LET A • 5
2 11 L E T B • 1 11
3 11 LET C% • 1 5
◄ II L E T D • 1 11
S Ii P R I NT A B e x D
Applesoft interprets line 50 as saying "display the value of integer
variable ABC%, followed by the value of real variable D," and displays
11 1 11
Since variable ABC% hasn't been assigned a value, its value is 0.
□ If a quoted string is the last item in the last statement of a line, the
closing quotation mark can be omitted, saving one byte:
1 11 P R I NT "TH I S I S T H E W A Y THE W O � L D
E N Di ,
2 11 P R I NT " N O T W I TH A BANG BUT A W H I MP E R
Utility programs called compilers are now available that convert Applesoft
programs to a form in which they run far faster than normally. However, a
compiled program can take as much as 50 percent more space than a
noncompiled one. The following hints should improve the execution speed
of your Applesoft programs. Notice that some of these same hints were
given in Section G.1 to save memory space. This means that in many cases
you can both shorten and speed up your programs at the same time.
□ This hint is probably ten times more important than any other in the list:
use real variables wherever possible instead ofinteger variables or
constants. It takes more time to convert an integer to its real-number
representation than to fetch the value of a real variable. This technique
is especially important within subroutines, loops, and other program
segments that are executed repeatedly.
□ Space for variables is allocated in the variable table in the order in which
they are encountered during the execution of the program. A line such as
5 A • I : B • A : C • B
places A first in the variable table, B second, and C third (assuming this
line is the first executed in the program). When these variables are
referred to later in the program, Applesoft has to search only one entry in
the variable table to find A, two entries to find B, and three entries to
find C. Try to arrange for those variables that your program refers to
most often to be located as early as possible in the variable table.
265
This appendix contains information on various details of Applesoft's
internal operation.
□ Section H.1, "Apple II Memory Map," summarizes the use of memory in
the Apple II and identifies areas of memory reserved for system use.
□ Section H.2, "Applesoft Memory Allocation," describes the way Applesoft
allocates memory for program and variable storage.
□ Section H.3, "Zero Page Use," details Applesoft's use of special locations
in page zero of the Apple II's memory.
□ Section H.4, "Keyword Tokens," lists the internal codes Applesoft uses to
represent keywords occurring in a program.
Memory
Range
From To Used For
$0000 $01FF System workspace; not advisable to use
0 511
$0200 $02FF Keyboard character buffer
51 2 767
$0300 $03CF Available for short machine-language programs
768 975
$03D0 $03FF Used by DOS and ProDOS
976 1023
$0400 $07FF Low-resolution graphics and text display, page 1
1024 2047
$0800 0BFF Low-resolution graphics and text display, page 2
2048 3071
$0800 $0XXX Applesoft program and variable space, where
XXX is the setting of HIMEM:
2048 XXX
$2000 $3FFF High-resolution graphics display, page 1
8192 16383
$4000 $5FFF High-resolution graphics display, page 2
16384 24575
$9600 $BFFF DOS
38400 49151
$COOO $CFFF Hardware 1/0 addresses
49152 53247
$D000 $F7FF Applesoft
53248 63487
$F800 $FFFF Apple II system Monitor
63488 65535
st,art of program
$0067 - $0068
103 - 104 --. - normally
$0800 (2048)
PROGRAM
end of program
$00AF - $00B0
175 - 176
st,art of variables
$0069 - $006A (LOMEM:)
105 - 106 SIMPLE
VARIABLES
st,art of arrays
$006B - $006C
-
107 - 108
-
ARRAYS
end of variables
$006D - $006E
109 - 110
FREE SPACE
st,art of strings
$006F - $0070
1 1 1 - 112
STRINGS
end of strings (HIMEM:)
$0073 - $0074
1 15 - 116
Simple Variables
Array Variables
•
•
277
This appendix describes the fonnats in which Applesoft displays or prints
numeric values. Numbers may not always be fonnatted in the way you
might expect; this is particularly true for numbers more than nine digits
long or for exceptionally small numbers.
Numeric values in Applesoft must be in the range -1*10 38 to 1•10 38. Any
A A
displays
1 . 23456788
on the screen.
Integers are always converted to real fonn before being used in arithmetic
calculations, and the results are converted back to integer fonn when
assigned to an integer variable. Conversion from real to integer fonn is by
truncation to the next lower integer, not by rounding.
Applesoft displays and prints numbers according to the following rules:
o If the number is negative, it is preceded by a minus sign (-); if it is O or
positive, no sign is used.
□ If the number is an integer with an absolute value from O to 999 999 999,
it is fonnatted as an integer.
□ If the number is not an integer and its absolute value is between .01 and
999 999 999.2, it is fonnatted with a decimal point in the usual way.
o In all other cases, the number is fonnatted in scientific notation.
The format Applesoft uses for scientific notation is shown in Figure 1-1.
I
SX .
I
X X X X X X X X E SDD
each x is a digit
sign of exponent
digits of exponent
281
The figures and tables on the following pages summarize Applesoft's
facilities for on-screen editing and cursor control. These features are
discussed briefly in Section 1.4, "Editing What You Type," and at greater
length in your Apple's owner's manual and theApplesoft Tutorial.
80-Column Users: If your model has 80-column display capabilities,
additional escape-mode features are available. If you have an Apple Ile
80-Column Text Card, see the manual that came with it. If you are an
Apple Ile owner, you can find the information in your owner's manual.
G 8 �
El 21 �
III 11 �
ill 10 i CONTROL I-QJ
Key Function
•O
285
The following table summarizes the differences in the Apple Ile's behavior
with and without the Apple I le 80-Column Text Card installed. Notice that
even 40-column display behaves somewhat differently with the 80-Column
Text Card installed and active than without it. See the BO-Column Text
Card Manual for further information.
287
This appendix summarizes the differences between Applesoft BASIC and
Apple's earlier Integer BASIC language. Section L.3 gives some hints on
converting programs written in Integer or other versions of BASIC to
Applesoft.
Applesoft BASIC can be used with two Apple disk operating systems:
DOS 3.3 and ProDOS. ProDOS does not support Integar BASIC. If you must
use Integer BASIC, you must use DOS 3.3. If you're using ProDOS only, you
can disregard this appendix.
IfInteger BASIC is loaded into your computer's memory, you can
switch from Applesoft to Integer BASIC by typing the command
I HT
To switch from Integer BASIC to Applesoft, type
FP
FP stands for floating-point, the name for the internal format used by
languages like Applesoft to represent real numbers.
Table L-1 lists Applesoft statements and functions that are not available in
Integer BASIC.
AUTO
DSP
MAN
MOD
Convert A s c 1 , J> • u
to A S • LEFTS C A $ , I - 1 > + X S + M I D$ C A $ ,
J + 1)
or
8 • B : C • B
□ Some versions of BASIC use a slash (/) instead of a colon (:) to separate
multiple statements on the same line. In converting to Applesoft, change
each such slash to a colon.
□ Programs that use the MAT (matrix arithmetic) functions available in
some versions of BASIC must be rewritten using FOR/NEXT loops to
perform the corresponding matrix operations.
295
This appendix discusses Applesoft's facilities for storing programs and
information on tape cassettes. For any of these features to work, all of the
following conditions must be present:
□ There must be a cassette tape recorder properly connected to the
computer (Apple II, Apple II Plus, or Apple Ile only).
□ The tape recorder must be turned on.
□ There must be a tape cassette properly mounted in the recorder.
□ The recorder must be set to RECORD or PLAY, depending on the
statement being executed.
None of the Applesoft tape operations checks for these conditions; if any
condition doesn't hold, the system may hang indefinitely. Only
I CONTROL H RESET I can interrupt a tape operation.
Occasionally a tape recorder does not work properly when both input and
output cables are plugged in at the same time. This problem originates from
a ground loop in the tape recorder itself, which prevents making a good
recording. The easiest solution is to unplug the output cable (usually labeled
MONITOR on the tape recorder) when recording. Such a ground loop causes
no trouble when reading a tape.
STORE MX
The STORE statement writes the contents of an integer or real array onto a
tape cassette. The name of the array (MX in the example above) follows the
keyword STORE, without a subscript. No prompting message or signal of
any kind is given; the tape recorder must already be turned on and set to
RECORD at the time the STORE statement is executed. Beeps signal the
start and end of the recording.
String arrays cannot be written with the STORE statement.
If the dimensions of the two arrays differ, RECALL may scramble the
information read into array B, or the program may halt with the message
? OUT O F M E M O R Y E R R O R .
•
•
•
•
•
•
•
299
The following is a complete listing of the postage rates program developed
in Chapter 8. A copy of this program is included on the ProDOS BASIC
Programming Examples disk.
1 B R E M P O STAGE R A T E S Name of program.
20 Colon leaves line empty.
3 0 R E M D E T E R M I M E S P O STAGE F E E S
What program does.
4 0 R E M F D R E X P R E S S , 1 ST C L A S S ,
5 0 R E M A M D P R I O R I TY MA I L Empty line inserted by embedding
I CONTROL Hl] (line feed) at end of
REM statement in line 50.
6 0 R E M V3 1 0 1 1 5 / 8 3 Number and date of this version
7 0 R E M BY J O H M S C R I BB L E M O M G E R & S C O T K AM I M S
Programmer's credit line.
1 0 0 R E M M E M U O F P O STAGE C L A S S E S
I CONTROL Hl] here.
1 1 0 HOME Begins with a clear screen.
1 2 0 T I TL E $ • " P O STAGE R A T E S "
1 3 0 P R I MT
1 4 0 HTAB 2 1 - L E M ( T I TL E $ ) / 2
Formula to center title.
150 P R I MT T I TL E $
1 60 VTAB 6
1 70 P R I MT " 1 . E X P R E S S "
1 80 P R I MT " 2 . F I R S T C L A S S "
1 90 P R I MT " 3 . P R I O R I TY "
200 P R I MT
210 P R I MT " 4 . E M D THE P R OGRAM"
The escape hatch.
3 0 0 REM I CONTROL Hl] here,
GET C L A S S OF MA I L I CONTROL HlJ here,
3 1 0 VTAB 1 4
3 2 0 P R I MT " P r e !l !l t h e numb e r o f y o u r c h o i c e : " ;
Semicolon keeps response on same
line,
330 GET cs Only one keypress needed-cuts
down on error possibilities; use of
string variable to get number avoids
type mismatch errors.
1 1 B S B EFLAG . 1
Suggests alternative.
Sets flag indicating inconsistent
weight/type; will be checked at
line 720.
1 1 B6B RETURN Ends routine.
1 2 B B B REM
P R I O R I TY MA I L C O N S I STE N C Y C H E C K
1 2 B 1 B IF WU • "P" THEN 1 2 B9B
If in pounds, then skips down.
1 2B2B I F W > 1 2 THEN 1 2B8B Skips down if weight is between 12
and 16 ounces.
1 2 B 3 B P R I NT
1 2 B 4 B P R I NT C H R $ C 7 ) ; C H R $ C 7 ) ; "TOO L I GHT F O R
P R I O R I TY MA I L - " Too light!
1 2 B S B P R I NT "TRY F I R S T C L A S S "
Suggests alternative.
1 2 B 6 B E F LAG = 1 Sets flag indicating inconsistent
weight/type; will be checked at
line 720.
1 2 0 1 0 GOTO 1 2 1 s e Branches to end of routine.
1 2Bae w • w / 16 Converts ounces to pounds.
1 2B9B I F W ( • 7B THEN 1 2 1 S B Final check: is item on the charts?
307
It's not hard to write programs that use the mouse pointing device. 'This
appendix is an introduction to what the mouse does and how to control it
from BASIC programs. There are two sample programs at the end of this
appendix.
A.Warning This appendix and the sample programs it contains assume you have a
mouse attached to your computer either through the special mouse port
(Apple Ile) or through port 4 (Apple II, Apple II Plus, Apple Ile). If you are
using a computer with expansion slots and the mouse card is plugged into
some port other than 4, adjust the port designation accordingly.
Also note that the sample code listed throughout this appendix sends
information to the video screen using the command
PR# 0
0.2 MOUSE.MOVE
The program named MOUSE.MOVE demonstrat.es the positions of the
mouse. This program reads and displays the current location of the mouse
and the status of the mouse button (whether it was just pressed, is
currently being pressed, and so on). Type in and run the program, then
move the mouse over your desk top and watch the coordinat.es change.
Press the mouse button and see the status change. Press any key to stop the
program.
1" HOME
2 1l P R I NT "Th 1 !I 1 !I a demo n !l t r a t i o n o f t h e
M o u !l e "
3 1l P R I NT C H R $ ( 4 ) ; "P R l 4 " : P R I NT C H R $ ( 1 )
4 1l P R I NT C H R S ( ◄ ) ; "P R I il "
S il P R I NT C H R $ C 4 ) ; " I H 1 4 "
6 1l I NPUT "" ; X , V , S
7 1l VTAB 1 " : P R I NT X ; " II t yn I I t 511 II
0.3 MOUSE.DRAW
This program is an expanded version of MOUSE.MOVE. With this program,
you can cause the mouse to draw pictures on the low-resolution graphics
screen. Pressing the mouse button clears the screen and lets you produce a
new picture.
18 R E M U !5 e !5 m o u !l e to d r aw l ow - r e !l o l u t i o n
g r a p h i c !I
188 G O S U B 1 B B B : R E M Tu r n o n t h e mou !5 e
118 P R I NT C H R $ C 4 ) ; " I N # 4 "
1 28 I NP U T '"' ; X , Y , S : R E M R e a d mou !5 e
p o !5 i t i o n
1 38 I F S • 1 THEN 1 8 8 : REM C l ear the
!S c r e e n
148 I F S < e THEN 3 8 8 : REM Time t o qu i t ?
1 58 R E M S c a l e t he p o !5 i t i o n
1 68 X • I NT e x 1 2 5 . 5 7 5 >
178 y - I NT C Y / 2 5 . 5 7 5 >
188 PLOT X , Y
198 GOTO 1 2 8
388 REM Chec k i f t i me t o qu i t
318 P O K E - 1 6368 , B : R E M C l e a r k eybo a r d
!l t o be
328 P R I NT CHRt C 4 ) ; " I N # B "
338 VTAB 2 2 : P R I NT "P r e !5 !5 R E T U R N t o c o n t
o r E S C t o qu i t "
348 VTAB 2 2 : HTAB 39 : G E T A $ : P R I NT
358 I F A $ • C H R $ C 1 3 ) T H E N H O M E : GOTO 1 1 8
368 I F A $ < > CHR$ C 27 ) THEN 348
378 R E M C l ea r !S c r e e n a n d t u r n o f f m o u !l e
388 TEXT : HOME
398 P R I NT C H R $ C 4 > ; " P R # 4 " : P R I NT C H R t C B )
488 P R I NT C H R $ C 4 ) ; " P R # B "
418 END
1 BBB R E M C l e a r !S c r e e n a n d i n i t a l i z e m o u !l e
18 18 H O M E : GR
1 828 COLOR• 15
1 838 P R I NT C H R $ C 4 > ; "P R ' 4 " : P R I NT C H R $ C 1 >
1 848 P R I NT C H R $ C 4 > ; "P R # B "
1 858 RETURN
acronym: A word formed from the application program: A program assembler: A language translator
initial letters of a name or phrase, that puts the resources and that converts a program written in
such as laser, from light capabilities of the computer to use assembly language into an
amplification by stimulated for some specific purpose or task, equivalent program in machine
emission of radiation. such as word processing, data-base language.
address: A number used to identify management, graphics, or assembly language: A low-level
something, such as a location in the telecommunications. Compare programming language in which
computer's memory. system program. individual machine-language
algorithm: A step-by-step application software: The instructions are written in a
procedure for solving a problem or component of a computer system symbolic form more easily
accomplishing a task. consisting of application programs. understood by a human programmer
argument: The value on which a than is machine language itself.
AND: A logical operator that function operates. BASIC: Beginner's All-purpose
produces a true result if both of its Symbolic Instruction Code; a
operands are true, a false result if arithmetic operator: An operator, high-level programming language
either or both of its operands are such as +, that combines numeric designed to be easy to leam and use.
false; compare OR, NOT. values to produce a numeric result; Two versions of BASIC are available
Apple II: A personal computer in compare relational operator, from Apple Computer for use with
the Apple II family, manufactured logical operator. the Apple II: Applesoft (built into
and sold by Apple Computer; array: A collection of variables the Apple II in firmware) and
generic name for all computers in referred to by the same name and Integer BASIC (provided on the OOS
the series. distinguished by means of 3.3 SYSTEM MASTER disk).
Applesoft: An extended version of numerical subscripts. . binary: The representation of
the BASIC programming language ASCII: American Standard Code numbers in terms of powers of 2,
used with the Apple II family of for Infonnation Interchange; a code using the two digits O and 1.
computers and capable of in which the numbers from O to 127 Commonly used in computers, since
processing numbers in floating-point stand for text characters, used for the values O and 1 can easily be
form. An interpreter for creating representing text inside a computer represented in physical form in a
and executing programs in and for transmitting text between variety of ways, such as the
Applesoft is built into the Apple II computers or between a computer presence or absence of current,
system in firmware. Compare and a peripheral device. positive or negative voltage, or a
Integer BASIC. white or black dot on the display
screen.
Glossary 317
binary file: A file containing "raw" boot disk: See startup disk. catalog: A list of all files stored on
information not expressed in text bootstrap: See boot. a disk; sometimes called a directory.
form; compare text file. cathode-ray tube: An electronic
binary operator: An operator that branch: To send program execution device, such as a television picture
combines two operands to produce a to a line or statement other than the tube, that produces images on a
result; for example, + is a binary next in sequence. screen coated with phosphors that
arithmetic operator, < is a binary buffer: An area of the computer's emit light when struck by a focused
relational operator, and OR is a memory reserved for a specific beam of electrons.
binary logical operator. Compare purpose, such as to hold graphical central processing unit: See
unary operator. information to be displayed on the processor.
bit: A binary digit (0 or 1); the screen or text characters being read
smallest possible unit of from some peripheral device. Often character: A letter, digit,
information, consisting of a simple used as an intermediary "holding punctuation mark, or other written
two-way choice, such as yes or no, area" for transferring information symbol used in printing or
on or off, positive or negative, between devices operating at displaying information in a form
something or nothing. different speeds, such as the readable by humans.
computer's processor and a printer character code: A number used to
bit bucket: The final resting place or disk drive. Information can be represent a text character for
of all information; see write-only stored in the buffer by one device processing by a computer system.
memory. and then read out by the other at a
body: The statements or different speed. code: (1) A number or symbol used
instructions malting up some bug: An error in a program that to represent some piece of
construct in a program, such as a causes it not to work as intended. information in a compact or easily
loop or a subroutine. processed form. (2) The statements
byte: A unit of information or instructions making up a
boot: To start up a computer by consisting of a fixed number of bits; program.
loading a program into memory on the Apple II, one byte consists of command: A communication from
from an external storage medium eight bits and can hold any value the user to a computer system
such as a disk. Often accomplished from O to 255. (usually typed from the keyboard)
by first loading a small program call: To request the execution of a directing it to perform some
whose purpose is to read the larger subroutine or function. immediate action.
program into memory. The program
is said to "pull itself in by its own card: See peripheral card. compiler: A language translator
bootstraps"; hence the term that converts a program written in a
bootstrapping or booting.
318 Glossary
high-level programming language control character: A character current output device: The
into an equivalent program in some that controls or modifies the way destination, such as the display
lower-level language (such as information is printed or displayed. screen or a printer, to which an
machine language) for later Control characters have ASCII Applesoft program is currently
execution. Compare interpreter. codes between O and 31 and are sending its output.
typed from the Apple II keyboard by
component: A part; in particular, a cursor: A marker or symbol
holding down the I CONTROL I key displayed on the screen that marks
part of a computer system. while typing some other character.
For example, the character where the user's next action will
computer: An electronic device for take effect or where the next
performing predefined � (ASCII code 13)
means "return to the beginning of character typed from the keyboard
(programmed) computations at high will appear.
speed and with great accuracy. the line" and is equivalent to the
I RETURN I key. data: Information; especially
computer system: A computer information used or operated on by
and its associated hardware, controller card: A peripheral card
that connects a device such as a a program.
firmware, and software.
printer or disk drive to the Apple II, debug: To locate and correct an
concatenate: Literally, "to chain and controls the operation of the error or the cause of a problem or
together"; to combine two or more device. malfunction in a computer system.
strings into a single, longer string Typically used to refer to
containing all the characters in the control variable: See index
variable. software-related problems; compare
original strings. troubleshoot.
conditional branch: A branch CPU: Central processing unit; see
that depends on the truth of a processor. decimal: The common form of
condition or the value of an number representation used in
crash: To cease operating everyday life, in which numbers are
expression; compare unexpectedly, possibly damaging or expressed in terms of powers of 10,
unconditional branch. destroying information in the using the ten digits O to 9.
constant: A symbol in a program process.
default: A value, action, or setting
representing a fixed, unchanging CRT: See cathode-ray tube. that is automatically used by a
value; compare variable. computer system when no other
current input device: The source,
control: The order in which the such as the keyboard or a modem, explicit information has been given.
statements of a program are from which an Applesoft program is For example, if a command to run a
executed. currently receiving its input. program from a disk does not
identify which disk drive to use, the
disk operating system automatically
uses the same drive that was used
in the last operation.
Glossary 319
deferred execution: The saving of dimension: The maximum size of display color: The color currently
an Applesoft program line for one of the subscripts of an array. being used to draw high- or
execution at a later time as part of a directory: A list of all files stored low-resolution graphics on the
complete program; occurs when the on a disk; sometimes called a display screen.
line is typed with a line number. catalog. display device: A device that
Compare immediate execution. exhibits information visually, such
delimiter: A character that is used disk: An information storage as a television receiver or video
medium consisting of a flat, circular monitor.
for punctuation to mark the magnetic surface on which
beginning or end of a sequence of information can be recorded in the display screen: The glass or
characters, and that therefore is not form of small magnetized spots, plastic panel on the front of a
considered part of the sequence similarly to the way sounds are display device, on which images are
itself. For example, Applesoft uses recorded on tape. displayed.
the double quotation mark ( ") as a
delimiter for string constants: the disk drive: A peripheral device edit: To change or modify; for
string "DOG" consists of the three that writes and reads information example, to insert, remove, replace,
characters D, 0, and G, and does not on the surface of a magnetic disk. or move text in a document.
include the quotation marks. In Disk II drive: A model of disk element: A member of a set or
written English, the space character drive made and sold by Apple collection; specifically, one of the
is used as a delimiter between Computer for use with the Apple II individual variables making up an
words. family of computers; uses array.
device: (1) A physical apparatus for 5-1/4-inch flexible ("floppy") disks. embedded: Contained within. For
performing a particular task or disk operating system: A example, the string "HUMPTY
achieving a particular purpose. (2) software system for the Apple II DUMPTY" is said to contain an
In particular, a hardware that enables the computer to control embedded space.
component of a computer system. and communicate with one or more
digit: (1) One of the characters O to Disk II drives. ending value: The value against
9, used to express numbers in which the index variable is tested
decimal form. (2) One of the disk-resident: Stored or held after each pass through a loop, to
characters used to express numbers permanently on a disk. determine when to stop repeating
in some other form, such as O and 1 display: (1) Information exhibited the loop.
in binary or O to 9 and A to F in visually, especially on the screen of error code: A number or other
hexadecimal. a display device. (2) To exhibit symbol representing a type of error.
information visually. (3) A display
device.
320 Glossary
error message: A message file: A collection of infonnation flag: A variable whose contents
displayed or printed to notify the stored as a named unit on a (usually 1 or 0, standing for true or
user of an error or problem in the peripheral storage medium such as false) indicate whether some
execution of a program. a disk. condition holds or whether some
file name: The name under which event has occurred, used to control
escape mode: A state of the Apple
the program's actions at some later
II family of computers, entered by a file is stored on a disk.
time.
pressing the I ESC I key, in which
firmware: Those components of a
certain keys on the keyboard take computer system consisting of floating-point: A method of
on special meanings for positioning programs stored permanently in representing numbers inside the
the cursor and controlling the read-only memory. Such programs computer in which the decimal
display of text on the screen. (for example, the Applesoft point (more correctly, the binary
interpreter and the Apple II Monitor point) is permitted to "float" to
escape sequence: A sequence of
program) are built into the computer different positions within the
keystrokes beginning with the I ESC I
at the factory; they can be executed number. Some of the bits within the
key, used for positioning the cursor
at any time but cannot be modified number itself are used to keep track
and controlling the display of text
or erased from main memory. of the point's position.
on the screen.
Compare hardware, software. Floating-point numbers of a given
execute: To perform or carry out a length cover a wider range than
specified action or sequence of fixed-point: A method of fixed-point numbers of the same
actions, such as those described by representing numbers inside the length, but with less precision.
a program. computer in which the decimal Compare fixed-point.
point (more correctly, the binary
expansion slot: A connector inside point) is considered to occur at a format: (1) The form in which
the Apple II, II Plus, and Ile fixed position within the number. infonnation is organized or
computers in which a peripheral Typically, the point is considered to presented. (2) To specify or control
card can be installed; sometimes lie at the right end of the number, so the format of infonnation. (3) To
called peripheral slot or port. that the number is interpreted as an prepare a blank disk to receive
integer. Fixed-point numbers of a information by dividing its surface
expression: A formula in a
given length cover a narrower range into tracks and sectors; also
program describing a calculation to
than floating-point numbers of the initialize.
be perfonned.
same length, but with greater function: A preprogrammed
FIFO: First in, first out. precision. Compare floating-point. calculation that can be carried out
on request from any point in a
program.
Glossary 321
GAME 1/0 connector: A special hardware: Those components of a high-order byte: The more
16-pin connector inside the Apple II, computer system consisting of significant half of a memory address
II Plus, and Ile computers, originally physical (electronic or mechanical) or other two-byte quantity. In the
designed for connecting hand devices. Compare software, Apple II's 6502 microprocessor, the
controls to the computer, but also firmware. low-order byte of an address is
used for connecting some other hertz: The unit of frequency of usually stored first and the
peripheral devices. Compare hand vibration or oscillation, also called high-order byte second.
control connector. cycles per second; named for the high-resolution graphics: The
graphics: (1) Information physicist Heinrich Hertz and display of graphics on the Apple II's
presented in the form of pictures or abbreviated Hz. The current display screen as a six-color array of
images. (2) The display of pictures provided by a standard power outlet points, 280 columns wide and 192
or images on a computer's display alternates at a rate of 60 hertz; that rows high.
screen. Compare text. is, it changes polarity 60 times each
second. The Apple II's 6502 Hz: See hertz.
hand control: An optional
peripheral device that can be microprocessor, for example, immediate execution: The
connected to the Apple II's hand operates at a clock frequency of 1 execution of an Applesoft program
control connector and has a rotating million hertz, or 1 megahertz (MHz). line as soon as it is typed; occurs
dial and a pushbutton; typically hexadecimal: The representation when the line is typed without a
used to control game-playing of numbers in terms of powers of 16, line number. Compare deferred
programs, but can be used in more using the sixteen digits 0 to 9 and A execution.
serious applications as well. to F. Hexadecimal numbers are implement: To realize or bring
hand control connector: A 9-pin easier for humans to read and about; for example, a language
connector on the Apple- II's back understand than binary numbers, translator implements a particular
panel, used for connecting hand but can be converted easily and language.
controls to the computer. Compare directly to binary form: each index: (1) A number used to
GAME 1/0 connector. hexadecimal digit corresponds to a identify a member of a list or table
sequence of four binary digits, or by its sequential position. (2) A list
hang: For a program or system to bits.
"spin its wheels" indefinitely, or table whose entries are identified
performing no useful work. high-level language: A by sequential position.
programming language that is index variable: A variable whose
hardcopy: Information printed on relatively easy for humans to
paper for human use. understand. A single statement in a value changes on each pass through
high-level language typically a loop; often called control variable
corresponds to several instructions or loop variable.
of machine language.
322 Glossary
infinite loop: A section of a executing programs in Integer K: Two to the tenth power, or 1024
program that repeats the same BASIC is included on the DOS 3.3 (from the Greek root kilo, meaning
sequence of actions indefinitely. SYSTEM MASTER disk, and is one thousand); for example, 64K
automatically loaded into the equals 64 times 1024, or 65,536.
information: Facts, concepts, or computer's memory when the
instructions represented in an computer is started up with that keyboard: The set of keys built
organized form. into the Apple II computer, similar
disk. Compare Applesoft. to a typewriter keyboard, for typing
initialize: (1) To set to an initial interactive: Operating by means of information to the computer.
state or value in preparation for a dialog between the computer
some computation. (2) To prepare a system and a human user. keystroke: The act of pressing a
blank disk to receive information by single key or a combination of keys
dividing its surface into tracks and interface: The devices, niles, or (such as � on the
sectors; also format. conventions by which one Apple II keyboard.
component of a system keyword: A special word or
input: (1) Information transferred communicates with another.
into a computer from some external sequence of characters that
source, such as the keyboard, a disk interpreter: A language translator identifies a particular type of
drive, or a modem. (2) The act or that reads a program written in a statement or command, such as
process of transferring such particular programming language RUN or PRINT.
information. and immediately carries out the kilobyte: A unit of information
actions that the program describes. consisting of lK (1024) bytes, or 8K
instruction: A unit of a Compare compiler.
machine-language or (8192) bits; see K.
assembly-language program inverse video: The display of text language: See programming
corresponding to a single action for on the computer's display screen in language.
the computer's processor to the form of black dots on a white (or
perform. other single phosphor color) language translator: A system
background, instead of the usual program that reads a program
integer: A whole number, with no white dots on a black background. written in a particular programming
fractional part; represented inside language and either executes it
the computer in fixed-point form. 1/0: Input/output; the transfer of
information into and out of a directly or converts it into some
Compare real number. other language (such as machine
computer. See input, output. language) for later execution. See
Integer BASIC: A version of the
BASIC programming language used 1/0 device: Input/output device; a interpreter, compiler,
with the Apple II family of device that transfers information assembler.
computers; older than Applesoft and into or out of a computer. See input,
capable of processing numbers in output, peripheral device.
integer (fixed-point) form only. An
interpreter for creating and
Glossary 323
LIFO: Last in, first out. low-order byte: The less memory: A hardware component
significant half of a memory address of a computer system that can store
line: See program line. or other two-byte quantity. In the information for later retrieval; see
line number: A number identifying Apple H's 6502 microprocessor, the main memory, random-access
a program line in an Applesoft low-order byte of an address is memory, read-only memory,
program. usually stored first and the read-write memory, write-only
high-order byte second. memory.
load: To transfer information from
a peripheral storage medium (such low-resolution graphics: The memory location: A unit of main
as a disk) into main memory for use; display of graphics on the Apple II's memory that is identified by an
for example, to transfer a program display screen as a sixteen-color address and can hold a single item
into memory for execution. array of blocks, 40 columns wide of information of a fixed size; in the
I
location: See memory location. and 48 rows high. Apple II, a memory location holds
machine language: The form in one byte, or eight bits, of
logical operator: An operator, which instructions to a computer information.
such as AND, that combines logical
values to produce a logical result; are stored in memory for direct memory-resident: (1) Stored
compare arithmetic operator, execution by the computer's permanently in main memory, as
relational operator. processor. Each model of computer firmware. (2) Held continually in
processor (such as the 6502 main memory even while not in use,
loop: A section of a program that is microprocessor used in the Apple II) as the disk operating system.
executed repeatedly until some has its own form of machine
condition is met, such as an index language. menu: A list of choices presented
variable reaching a specified ending by a program, usually on the display
value. main memory: The memory screen, from which the user can
component of a computer system select.
loop variable: See index that is built into the computer itself
variable. and whose contents are directly MHz: Megahertz; one million hertz.
accessible to the processor. See hertz.
low-level language: A
programming language that is mask: A pattern of bits for use in microcomputer: A computer, such
relatively close to the form that the bit-level logical operations. as the Apple II, whose processor is a
computer's processor can execute microprocessor.
directly. Low-level languages microprocessor: A computer
available for the Apple II include processor contained in a single
6502 machine language and 6502 integrated circuit, such as the 6502
assembly language. microprocessor used in the Apple II.
324 Glossary
mode: A state of a computer or operand: A value to which an page: (1) A screenful of information
system that determines its behavior. operator is applied. on a video display, consisting on the
modem: Modulator/demodulator; a operating system: A software Apple II of 24 lines of 40 or 80
peripheral device that enables the system that organizes the characters each. (2) An area of main
computer to transmit and receive computer's resources ai:ld memory containing text or graphical
information over a telephone line. capabilities and makes them information being displayed on the
available to the user or to screen.
monitor: See video monitor. application programs running on the pass: A single execution of a loop.
Monitor program: A system computer.
program built into the Apple II in peek: To read information directly
firmware, used for directly operator: A symbol or sequence of from a location in the computer's
inspecting or changing the contents characters, such as + or AND, memory.
of main memory and for operating specifying an operation to be
performed on one or more values peripheral: At or outside the
the computer at the boundaries of the computer itself,
machine-language level. ( the operands) to produce a result;
see arithmetic operator, either physically (as a peripheral
nested loop: A loop contained relational operator, logical device) or in a logical sense (as a
within the body of another loop and operator, unary operator, peripheral card).
executed repeatedly during each binary operator. peripheral card: A removable
pass through the containing loop. OR: A logical operator that printed-circuit board that plugs into
nested subroutine call: A call to a produces a true result if either or one of the Apple II, II Plus, or Ile's
subroutine from within the body of both of its operands are true, a false expansion slots and expands or
another subroutine. result if both of its operands are modifies the computer's capabilities
f alse; compare AND, NOT. by connecting a peripheral device or
nibble: A unit of information equal performing some subsidiary or
to half a byte, four bits, or fifty output: (1) Information transferred peripheral function.
cents; can hold any value from O to from a computer to some external
15. Sometimes spelled nybble. destination, such as the display peripheral device: A device, such
as a video monitor, disk drive,
NOT: A unary logical operator that screen, a disk drive, a printer, or a printer, or modem, used in
produces a true result if its operand modem. (2) The act or process of conjunction with a computer. Often
is false, a false result if its operand transferring such information.
(but not necessarily) physically
is true; compare AND, OR. separate from the computer and
null string: A string containing no connected to it by wires, cables, or
characters. some other form of interface,
typically by means of a peripheral
card.
Glossary 325
peripheral slot: See expansion printed-circuit board: A programmer: The human author ·
slot. hardware component of a computer . of a program; one who writes
plotting vector: A code or other electronic device, programs.
representing a single step in consisting of a flat, rectangular
piece of rigid material, commonly programming: The activity of
drawing a shape on the fiberglass, to which integrated writing programs.
high-resolution graphics screen, circuits and other electronic
specifying whether to plot a point at programming language: A set of
components are connected. rules or conventions for writing
the current screen position and in
what direction to move (up, down, printer: A peripheral device that programs.
left, or right) before processing the writes information on paper in a prompt: To remind or signal the
next vector. See shape defmition, form easily readable by humans or user that some action is expected,
shape table. literate monkeys. typically by displaying a distinctive
point of call: The point in a processor: The hardware symbol, a reminder message, or a
program from which a subroutine or component of a computer that menu of choices on the display
function is called. performs the actual computation by screen.
directly executing instructions prompt character: (1) A text
pointer: An item of information represented in machine language
consisting of the memory address of character displayed on the screen to
some other item. For example, and stored in main memory. prompt the user for some action.
Applesoft maintains internal program: (1) A set of instructions Often also identifies the program or
pointers to (among other things) the describing actions for a computer to component of the system that is
most recently stored variable, the perform in order to accomplish some doing the prompting; for example,
most recently typed program line, task, conforming to the rules and the prompt character J is used by
and the most recently read DATA conventions of a particular the Applesoft BASIC interpreter, >
item. programming language. In by Integer BASIC, and • by the
Applesoft, a sequence of program system Monitor program. Also called
poke: To store information directly prompting character. (2) Someone
in a location in the computer's lines, each with a different line
number. (2) To write a program. who is always on time.
memory.
program line: The basic unit of an prompt message: A message
pop: To remove the top entry from displayed on the screen to prompt
a stack. Applesoft program, consisting of one
or more statements separated by the user for some action. Also called
precedence: The order in which colons (:). prompting message.
operators are applied in evaluating push: To add an entry to the top of
an expression. a stack.
326 Glossary
queue: A list in which entries are read-only memory: Memory reserved word: A word or
added at one end and removed at whose contents can be read but not sequence of characters reserved by
the other, causing entries to be written; used for storing firmware. a programming language for some
removed in FIFO (first-in-first-out) Information is written into read-only special use, and therefore
order; compare stack. memory once, during manufacture; unavailable as a variable name in a
it then remains there permanently, program.
RAM: See random-access even when the computer's power is
memory. turned off, and can never be erased resident: See memory-resident,
random-access memory: Memory or changed. Compare read-write disk-resident.
in which the contents of individual memory, random-access return address: The point in a
locations can be referred to in an memory, write-only memory. program to which control returns on
arbitrary or random order. This completion of a subroutine or
read-write memory: Memory
term is often used incorrectly to whose contents can be both read function.
refer to read-write memory, but and written; often misleadingly
strictly speaking both read-only and ROM: See read-only memory.
called random-access memory, or
read-write memory can be accessed RAM. The information contained in routine: A part of a program that
in random order. This misuse of the read-write memory is erased when accomplishes some task subordinate
term random-access is an attempt to the computer's power is turned off, to the overall task of the program.
confuse new users, creating a rite of and is permanently lost unless it
passage and an excellent market for run: (1) To execute a program. (2)
has been saved on a more To load a program into main
glossaries of computer terms. permanent storage medium, such as memory from a peripheral storage
Compare read-only memory, a disk. Compare read-only
read-write memory, write-only medium, such as a disk, and
memory, random-access execute it.
memory. memory, write-only memory.
read: To transfer information into save: To transfer information from
real number: A number that may main memory to a peripheral
the computer's memory from � include a fractional part; storage medium for later use.
source external to the computer represented inside the computer in
(such as a disk drive or modem) or floating-point form. Compare scientific notation: A method of
into the computer's processor from a integer. expressing numbers in terms of
source external to the processor powers of 10, useful for expressing
(such as the keyboard or main relational operator: An operator, numbers that may vary over a wide
memory). such as > , that compares numeric range, from very small to very large.
values to produce a logical result; For example, the number of atoms
compare arithmetic operator, in a gram of hydrogen is
relational operator. approximately 6.02E23, meaning
Glossary 327
6.02 times 10 to the 23rd power. simple variable: A variable that is statement: A unit of a program in a
(The letter E stands for exponent.) not an element of an array. high-level language specifying an
The number is easier to understand soft switch: A means of changing action for the computer to perfonn,
in this fonn than in the fonn some feature of the Apple II from typically corresponding to several
602000000000000000000000. within a program; specifically, a instructions of machine language.
screen: See display screen. location in memory that produces step value: The amount by which
some special effect whenever its the index variable changes on each
scroll: To change the contents of contents are read or written. pass through a loop.
all or part of the display screen by
shifting infonnation out at one end software: Those components of a stepwise refmement: A technique
(most often the top) to make room computer system consisting of of program development in which
for new infonnation appearing at programs that determine or control broad sections of the program are
the other end (most often the the behavior of the computer. laid out first, then elaborated step
bottom), producing an effect like Compare hardware, firmware. by step until a complete program is
that of moving a scroll of paper past space character: A text character obtained.
a fixed viewing window. See whose printed representation is a string: An item of infonnation
viewport, window. blank space, typed from the consisting of a sequence of text
seed: A value used to begin a keyboard by pressing the I�s-P- -E�i
AC characters.
repeatable sequence of random bar.
numbers. strobe: (1) An event, such as a
stack: A list in which entries are change in a signal, that triggers
shape definition: A coded added or removed at one end only some action. (2) A signal whose
description of a shape to be drawn (the top of the stack), causing them change is used to trigger some
on the high-resolution graphics to be removed in LIFO action.
screen, consisting of one or more (last-in-first-out) order; compare
plotting vectors. See shape table, queue. subroutine: A part of a program
plotting vector. that can be executed on request
starting value: The value assigned from any point in the program, and
shape table: A collection of one or to the index variable on the first that returns control to the point of
more shape definitions, together pass through a loop. the request on completion.
with their indices.
startup disk: A disk containing subscript: An index number used
shape table index: A list giving software recorded in the proper to identify a particular element of
the memory addresses of the shapes fonn to be loaded into the Apple H's an array.
in a shape table. memory in order to set the system
into operation. Sometimes called a
boot disk; see boot.
328 Glossary
substring: A string that is part of truncate: To shorten by discarding video: (1) A medium for
another string. a part; specifically, to convert a real transmitting information in the form
syntax: The rules governing the number to the next lower integer. of images to be displayed on the
structure of statements or unary operator: An operator that screen of a cathode-ray tube. (2)
instructions in a programming applies to a single operand; for Information organized or
language. example, the minus sign (-) in a transmitted in video form. (3) An
negative number such as -6 is a early space pioneer.
system: A coordinated collection of unary arithmetic operator. Compare video monitor: A display device
interrelated and interacting parts binary operator.
organized to perform some function capable of receiving video signals by
or achieve some purpose. unconditional branch: A branch direct connection only, and that
that does not depend on the truth of cannot receive broadcast signals
system program: A program that any condition; compare such as commercial television. Can
makes the resources and conditional branch. be connected directly to the Apple II
capabilities of the computer computer as a display device.
available for general purposes, such user: The person operating or viewport: All or part of the display
as an operating system or a controlling a computer system. screen, used by an application
language translator. Compare user interface: The rules and program to display a portion of the
application program. conventions by which a computer information (such as a document,
system software: The component system communicates with the picture, or worksheet) that the
of a computer system consisting of person operating it. program is working on. Compare
system programs. value: An item of information that window.
text: (1) Information presented in can be stored in a variable, such as a window: (1) The portion of a
the form of characters readable by number or a string. collection of information (such as a
humans. (2) The display of variable: (1) A location in the document, picture, or worksheet)
characters on the Apple H's display computer's memory where a value that is visible in a viewport on the
screen. Compare graphics. can be stored. (2) The symbol used display screen; compare viewport.
text ftle: A file containing in a program to represent such a (2) A viewport. (3) A flat,
information expressed in text form; location; compare constant. rectangular panel, usually made of
compare binary me. silica, used in many archaic
structures as a human-to-nature
text window: An area on the Apple interface.
H's display screen within which text
is displayed and scrolled.
Glossary 329
wraparound: The automatic write-only memory: A form of Farnsfarfle's critics have denounced
continuation of text from the end of computer memory into which his project as a six-million-dollar
one line to the beginning of the next, information can be stored but never, boondoggle, but his defenders point
as on the display screen or a printer. ever retrieved, developed under out that this excess information
write: To transfer information from government contract in 1975 by would have cost more than 250
the computer to a destination Professor Hornberg T. Farnsfarfle. billion dollars to store in
external to the computer (such as a Farnsfarfle's original prototype, conventional media. Compare
disk drive, printer, or modem) or approximately one inch on each read-only memory, read-write
side, has so far been used to store memory, random-access
from the computer's processor to a more than 100 trillion words of memory.
destination external to the processor surplus federal information.
(such as main memory).
330 Glossary
Index
Index 331
ATN function 38, 196 integers 36-37 COLOR= statement 123-124, 197
as reserved word 232 length of strings 76-77 as reserved word 232
audio output 118, 256-257 logarithm 39, 207 color(s)
auto-repeat 17 sine 37, 215 in high-resolution graphics 133-134,
square root 37, 215 202
B string length 206 in low-resolution graphics 123-124,
tangent 38, 217 129, 202, 214
\ (backslash) 3, 16 CALL statement 164-165, 197 setting with COLOR= 197
backspace (G) 17 CAN'T CONTINUE message 238 monochrome display and 124, 133
BAD SUBSCRIPT message 237 canceling reading 129
BASIC lines with � 16 , (comma) 105
Applesoft BASIC and 2 A (caret), for exponentiation 29 INPUT and 93
Converting programs to Applesoft cassette tape 296-298 PRINT and 104
BASIC 291-293 arrays and 297-298 canceling TRACE with 173
See also Integer BASIC I CONTROL H RESET I and 296 resetting
BASIC Programming With ProDOS LOAD and 13 HIMEM: with 169
xxvi loading from 297, 298 LOMEM: with 170
bell loading shape tables from 215, 298 comma tabbing, differences between
using � to sound 118 reading from 100, 297-298 40- and 80-colurnn display and
bit masking 167, 218 RECALL and 212 286
blank lines 105 SAVE and 12 commands
eliminating 104 storing . BSAVE 149
blocks, _plotting 125-126 arrays on 216 CLEAR 8, 197
branching 44-49 shape tables on 156-157 CONT 15, 197
condition.al 46-49, 59-60, 204, 209 writing to 119, 296, 297 DEL 5-6, 198
to lines 46-47 changing lines 6 LIST 9-10, 206
to subroutines 59-60 characters, inputting single 94-95 LOAD 12-13, 100, 207, 297
unconditional 44-45, 201 CHR$ function 83, 197 NEW 7-8, 208
to variables 45 CLEAR command 8, 197 NOTRACE 174, 208
BSAVE command 149 clearing RUN 10-11, 213
graphics pages 253-254 SAVE 11-12, 296
C memory 7-8, 208 TRACE 173, 217
screen 19, 203 comments
calculating text window 109, 247 See REM statement
absolute value 36, 196 variables (unused) 171-172 comparing strings 75-76 compilers 263
arc tangent 38, 196 : (colon) concatenating strings 77-79
cosine 37, 198 INPUT and 93 LEN and 78
exponents 38, 199 to separate statements 4 PRINT and 104
332 Index
condensing programs 260-264 D E
conditional branching 46-49, 59-60,
204, 209 DATA statement 96-98, 198 editing programs 16-20
constants, string 7 4-84 control characters and 98 80-column display, differences from
CONT command 15, 197 debugging 172-174, 257-258 40-column display 286
control characters NOTRACE and 174, 208 80-Column Text Card
DATA and 98 TRACE and 173, 217 , (comma) and 105
INPUT and 91 DEF FN statement 40-42, 198 FLASH and 116
control stack 8, 60, 65 deferred execution 2, 4 HTAB and 113
memory allocation and · 269-271 defining PR# and 102
arrays 199 elements, array 26, 70
�
stopping functions 40-42 END statement 67, 199
infinite loops with 45, 53 DEL command 5-6, 198 enhanced Apple Ile, upper/lowercase
programs with 13, 14 deleting lines 5-6, 198 and 3
� using to sound bell 118 DIM statement 72, 199 = (equal sign), with reserved words
I CONTROL KI], REM statements and dimensioning arrays 72 232
185 disk operating system = (equal to) 31-35
I CONTROL H RESET I See DOS, ProDOS error code 62-63
cassette tape and 296 display error handling 62-66
CONT and 15 differences between 40- and soft switches and 257-258
stopping programs with 14-15 80�column 286 error messages 236-242
� interrupting screen monochrome 124, 133 BAD SUBSCRIPT 237
output with 13 DIVISION BY ZERO message 238 CAN'T CONTINUE 238
�. canceling lines with 16 $ (dollar sign) in string variable names DIVISION BY ZERO 238
converting 26 FORMULA TOO COMPLEX 238
programs to Applesoft BASIC DOS ILLEGAL DIRECT 238
291-293 IN# and 87, 102 ILLEGAL QUANTITY 239
strings 81-84, 216 PR# and 87, 102 NEXT WITHOUT FOR 239
coordinates [D (Down-Arrow key) 17-18 OUT OF DATA 239
in high-resolution graphics 134-136 DRAW statement 152-153, 199 OUT OF MEMORY 240
in low-resolution graphics 125-126 animation with 154 OVERFLOW 240
COS function 37, 198 See also XDRAW REDIM'D ARRAY 240-241
cosine, calculating 37, 198 RETURN WITHOUT GOSUB 241
cursor STRING TOO LONG 241
moving 17-20, 104-105, 247-249, SYNTAX ERROR 241
282-283 TYPE MISMATCH 241
position of 248 UNDEF'D FUNCTION 242
POS �d 114 UNDEF'D STATEMENT 242
in windo\vs 248-249
Index 333
I esc I (Escape key) 18 free memory 171-172, 201 G
escape mode 18-20, 282-283 functions
differences betw:een 40- and ABS 36, 196 game paddle
80-column display and 286 arithmetic 35-42 See hand controls
executing ASC 84, 196 GET statement 94-95, 201
machine-language subroutines with ATN 38, 196, 232 � and 14
CALL 164-166, 197 CHR$ 83, 197 GOSUB statement 55-60, 201
programs 10-1 1, 213 cos 37, 198 GOTO statement 44-46, 201
subroutines with GOSUB 201 defining 40-42 GR statement 122-123, 202
execution EXP 38, 199 graphics
deferred 2, 4 FRE 171-172, 201 display, switching from text to 109
immediate 2, 3 INT 36-37, 205 full screen 123, 134
interrupting 167-168, 192-193, 218 LEFT $ 79, 206 HGR and 130
resuming 15, 197, 212 LEN 76-77, 78, 206 high resolution 130-138, 202, 203
stopping 199, 216 LOG 39, 207 low resolution 122-129, 197, 202,
tracing 173-174, 208, 217 memory allocation and 269-271 210, 214, 218
EXP function 38, 199 MID$ 80, 207 mixing with text 126, 134, 136-137
exponents, calculating 38, 199 naming 41 modes, switching between 251-253
expressions 28-35 PDL 99-100, 209 pages 130-132, 137-138, 202, 250-254
EXTRA IGNORED message 89, 95 PEEK 162-163, 210 in text mode (MouseText) 158-159
POS 114, 211 > (greater than) 31-35
F RIGHT $ 81, 213 > = (greater than or equal to) 31-35
RND 39-40, 213
FLASH statement 115-116, 200 SCRN 129, 214, 232 H
differences between 40- and SGN 36, 214
80-column display and 286 SlN 37, 215 hand controls 99-100, 254-255
FN 200 SPC 109-110, 215, 232 annunciator outputs and 1 19
FOR statement 52-53, 200 SQR 37, 215 PDL and 99-100, 209
.formatting STR$ 82, 216 utility strobe and 119
numbers 106-108, 278-280 string conversion 81-84 HCOLOR= statement 133-134, 202
output 103-106 substring 79-81 as reserved word 232
text 108-1 17 TAB 111-112, 216 HGR statement 130-131, 202
FORMULA TOO COMPLEX message TAN 38, 217 HGR2 statement 131-132, 202
238 trigonometric 37-38 high memory 168-169, 203
40-column display, differences from user defined 198, 200 high-resolution graphics 130-138, 202
80-column display 286 USR 165-166, 217 color in 133-134
fractions 30 VAL 82-83, 218 coordinates in 134-136
FRE function 171-172, 201 pages 137-138, 202
plotting
lines in 135-136
points in 134, 203
334 Index
high-resolution page 2, GR and 123 inputting line numbers 3, 4
HIMEM: statement 168-169, 203 data from within programs 96-98 lines
as reserved word 232 single characters 94-95 adding 4
HLIN statement 127, 203 INT function 36-37, 205 blank 105
HOME statement 109 1 203 integer(s) 205 eliminating 104
horizontal lines, in low-resolution arithmetic 23 branching to 46-47
graphics 127, 203 calculating 36-37 canceling with � 16
HPLOT statement 134-136, 203 Integer BASIC, differences from changing 6_
HTAB statement 1 12-1 13, 204 Applesoft BASIC 288-293 deleting 5-6, 198
differences between 40- and See also BASIC horizontal 127, 203
SO-column display and 286 interrupting plotting in high-resolution graphics
See also TAB, VTAB execution 167-168, 192-193, 218 135-136
programs 13-15, 14-15 program 2, 3
I screen output 13 vertical 128, 218
INVERSE statement 115-1 16, 205 LIST command 9-10, 206
IF ... THEN statement 47-49, 204 differences between 40- and listing programs 9-10, 206
ILLEGAL DIRECT message 238 SO-column display and 286 LOAD command 12-13, 100, 207, 297
ILLEGAL QUANTITY message 239 inverse tangent loading
immediate execution 2, 3 See arc tangent from cassette tape 297, 298
IN# statement 86-87, 205 programs 12-13, 207
DOS and 87, 102 J, K shape tables 146-150
ProDOS and 87, 102 from cassette tape 215, 298
as reserved word 232 keyboard LOG function 39, 207
index, shape table 144-145 input from 201, 249 logarithm, calculating 39, 207
index variable 50 keyboard introduction disk xxvi logical operators 32-35
infinite loops, stopping 45, 53 keyword tokens 274-275 LOMEM: statement 170, 207
input 86-100 as reserved word 232
accepting 88-94 L loops 50-55
cassette tape 100 infinite, stopping 45, 53
designating source of 86-87, 205 G (Left-Arrow key) 17 -18 nesting 54-55
keyboard 201, 249 LEFT$ function 79, 206 loudspeaker
numeric 91-94 LEN function 76°77, 206 See speaker
string 90-91 concatenating strings and 78 low memory 170, 207
INPUT statement 88-94, 205 length of strings, calculating 76-77 low-resolution graphics 122-129, 202
: (colon) and 93 < (less than) 31-35 colors in 214
, (comma) and 93 < = (less than or equal to) 31-35 setting with COLOR= 197
control characters and 91 LET statement 27-28 coordinates in 125-126
multiple 89 See also assignment statements plotting in 210
vertical lines in 218
Index 335
lowercase 3, 18 menus, designing 184 numeric
INVERSE and 115 MID$ function 80, 207 input 91-94
strings and 74 - (minus sign), for subtraction 29 values 106-108
monochrome display, colors and 124, variables, RUN and 11
133
M mouse 308-315 0
using 308-311
machine-language subroutines, MOUSE.ORAW program 312-314 ON...GOSUB statement 59-60, 209
executing with CALL 164-166, 197 MOUSE.MOVE program 311-312 ON ... GOTO statement 46-47, 209
manuals MouseText 158-159 IF ... THEN and 48
Apple Backpack: Humanized multidimensional arrays 72-74 ONERR GOTO statement 62-64, 209
Programming in BASIC xxvii multiple 6 key (@]) 100, 254
Applesoft Tutorial xxvi INPUT statements 89 operating system
BASIC Programming With statements 4-5 See DOS, ProDOS
ProDOS xxvi operators
keyboard introduction disk xxvi N arithmetic 29-30
owner's manual xxvi logical 32-35
map, memory (Apple II) 267 naming functions 41 precedence of 33-35
masking 167, 218 nesting relational 30-35, 75-76
memory loops 54-55 OR 32-35
addresses 162-165 subroutines 57 OUT OF DATA message 239
allocation of 268-271 NEW command 7-8, 208 OUT OF MEMORY message 240
altering 163-165, 210, 244 NEXT statement 53-54, 55, 208 output(s) 101-119
clearing 7-8, 208 NEXT WITHOUT FOR message 239 annunciator 119, 255-256
examining 162-163, 210 NORMAL statement 116, 208 audio 118, 256-257
free 171-172, 201 NOT 32-35 cassette tape 119
high 168-169, 203 < > (not equal to) 31-35 formatting 103-106
low 170, 207 NOTRACE command 174, 208 specifying destination of 101-103,
managing 149, 157, 168-172 null string 75 211
map (Apple II) 267 numbers speed of 117, 215
page2, high resolution, GR and 123 formatting 106-108, 278-280 OVERFLOW message 240
page zer0 271-27 4 line 3, 4 owner's manual xxvi
pages, graphics 130-132, 202, random 39-40, 213
250-254 real 23-24, 23-24 p
protecting 203 rounding 37
saving 260-264 paddles
See hand controls
page 2, high resolution, GR and 123
336 Index
page zero 271-27 4 debugging 172-174, 208, 217, 257-258 reading
pages, graphics 130-132, 202, 250-254 editing 16-20 from cassette tape 297-298
clearing 253-254 executing 10-11, 213 colors 129
protecting 137-138 execution, stopping 67, 199, 216 hand-control buttons 100
parentheses, precedence and 35 with � 13, 14 real
PDL function 99-100, 209 with I CONTROL H RESET I 14-15 numbers 23
PEEK function 162-163, 210 flow, controlling 44-49 variables 23-24
planning programs 176-183 inputting data from within 96-98 RECALL statement 100, 212, 297-298
PLOT statement 125-126, 210 interrupting 13-15, 14-15 REDIM'D ARRAY message 240-241
plotting line 2, 3 REENTER message 90
lines, in high-resolution graphics listing 9-10, 206 relational operators 30-35
135-136 loading 12-13, 207 comparing strings with 75-76
in low-resolution graphics 210 MOUSE.DRAW 312-314 REM statement 6, 184, 185, 212
points, in high-resolution graphics MOUSE.MOVE 31 1-312 I CONTROL H1) and 185
134-136, 203 planning 176-183 reserved words 232-233
vectors in shape tables 139-140 postage rates 176-193, 300-306 memory allocation and 269-271
+ (plus sign), for addition 29 resuming 13-15 See also tokens
points, plotting in high-resolution saving 11, 214 reset vector 15
grpahics 134-136, 203 specifications of 176-180 resetting
POKE statement 163-164, 210 prompt character (I) 2 variables 8, 197, 208
POP statement 58-59, 60-62, 65, 210 prompting for input 88-89 RESTORE statement 98-99, 212
POS function 114, 211 protecting RESUME statement 65, 212
postage rates program 176-193, high-resolution graphics 137-138 resuming
300-306 memory 203 execution 15, 197, 212
PR# statement 101-103, 211 shape tables 149 normal error handling 65-66
DOS and 87, 102 PUSH 58-59 programs 13-15
ProOOS and 87, 102 return address 58, 59, 60
as reserved word 232 Q RETURN statement 55-60, 212
precedence of operators 33-35 RETURN WITHOUT GOSUB message
PRINT statement 103-106, 211 ? (question mark), instead of PRINT 241
? (question mark) instead of 106 106 reversed text
spaces in 109-110 See FLASH, INVERSE
ProDOS R G (Right-Arrow key) 17-18
IN# and 87, 102 ] (right bracket), as prompt character
PR# and 87, 102 random numbers 39-40, 213
READ statement 96-98, 211 2
program(s) 2 RIGHT$ function 81, 213
condensing 260-264 RND function 39-40, 213
converting to Applesoft BASIC ROT= statement 155-156, 213
291-293 as reserved word 232
Index 337
rotating shapes 155-156, 213 shapes END 67, 199
rounding numbers 37 drawing 152-154, 199 FLASH 115-116, 200, 286
RUN command 10-11, 213 erasing 153, 219 FOR 52, 200
rotating 155-156, 213 GET 14, 94-95, 201
s scale of 154-155, 214
SHLOAD statement 100, 156-157, 215,
GOSUB 55-60, 201
GOTO 44-46, 201
SAVE command 11-12, 296 298 GR 122-123, 202
saving sign, determining 36, 214 HCOLOR= 133-134, 202, 232
memory 260-264 SIN function 37, 215 HOR 130-131, 202
programs 11, 214 sine, calculating 37, 215 HGR2 131-132, 202
shape tables 149-150 / (slash), for division 29 HIMEM: 168-169, 203, 232
scale of shapes 154-155, 214 soft switches 244, 250-251 HLIN 127, 203
SCALE= statement 154-155, 214 a key (rn) 100, 254 HOME 109, 203
as reserved word 232 error handling and 257-258 HPLOT 134-136, 203
scientific notation 107-108 sound See speaker 118, 256-257 HTAB 112-113, 204, 286
screen spaces 215 IF ... THEN 47-49, 204
clearing 19, 203 with PRINT 109-110 IN# 86-87, 102, 205
display 286 SPC function 109-110, 215 INPUT 88-94, 205
output, interrupting 13 as reserved word 232 INVERSE 1 15-1 16, 205, 286
text 244 ; (semicolon) and 110 LET 27-28
SCRN function 129, 214 speaker 118, 256-257 LOMEM: 170, 207, 232
as reserved word 232 specifications of programs 176-180 multiple 4-5
scrolling text 247 specifying output destination 101-103, NEXT 53-54, 55, 208
; (semicolon) 211 NORMAL 1 16, 208
PRINT and 104 SPEED= statement 117, 215 ON ... GOSUB 59-60, 209
SPC and 110 as reserved word 232 ON ... GOTO 46-47, 48, 209
TAB and 112 SQR function 37, 215 ONERR GOTO 62-64, 209
SGN function 36, 214 square root, calculating 37, 215 PLOT 125-126, 210
shape tables 138-157 stack See control stack 8, 60, 65 POKE 163-164, 210
creating 138-150 statement( s) 2 POP 58-59, 60-62, 65, 210
index of 144-145 assignment 27-28, 196 PR# 87, 101-103, 211
loading 146-149, 149-150 CALL 164-165, 197 PRINT 103-106, 109-1 10, 211
from cassette tape 215, 298 COLOR= 123-124, 197, 232 READ 96-98, 211
plotting vectors in 139-140 DATA 96-98, 198 RECALL 100, 212, 297-298
protecting 149 DEF FN 40-42, 198 REM 6, 184, 185, 212
saving 149-150 DIM 72, 199 repeated
storing on cassette tape 156-157 DRAW 152-153, 154, 199 RESTORE 98-99, 212
using 151-157 RESUME 65, 212
338 Index
RETURN 55-60, 212 variables 23-24, 25-26, 75 text
ROT= 155-156, 213, 232 RUN and 11 formatting 108-117
SCALE= 154-155, 214, 232 See also substrings HLIN in 127
SHLOAD 100, 156-157, 215, 298 STRING TOO LONG message 241 mixing with graphics 126, 134,
SPEED= 1 17, 215, 232 strobe, utility 119, 255 136-137
STOP 67, 216 · subroutines 55-62 reversed
STORE 216, 297 branching to 59-60 See FLASH, INVERSE
TEXT 109, 123, 217 ending 212 screen 244
VLIN 128, 218 executing with GOSUB 201 scrolling 247
VTAB 113-114, 218 machine language, executing with VLIN in 128
WAIT 166-168, 218 CALL 164-166, 197 text card, 80 column
XDRAW 153-154, 219 nesting 57 FLASH and 116
step value 52 user defined 165-166, 217 HTAB and 113
STOP statement 67, 216 subscripts, array 26, 70 text display, switching from graphics
stopping substring(s) to 109
infinite loops 45, 53 functions 79-81 text mode, graphics in (MouseText)
program execution 67, 199, 216 See also strings 158-159
with � 13, 14 switches, soft 244, 250-251, 257-258 TEXT statement 109, 217
with I CONTROL H RESET I 14-15 switching high-resolution page 2 and 123
STORE statement 216, 297 between graphics modes 251-253 text window 19, 109-110, 163-164, 203
storing from graphics to text display 109 clearing 109, 247
arrays on cassette tape 216 syntax definitions 222-225 HTAB and 112
shape tables on cassette tape SYNTAX ERROR message 241 setting 245-246
156-157 system THEN statement
STR$ function 82, 216 utilities 162-168 See IF...THEN
string(s) 7 4-84 TO, as reserved word 232
alphabetizing 76 T tokens 274-275
calculating length of 206 See also reserved words
comparing 75-76 TAB function 111-112, 216 TRACE command 173, 217
concatenating 77-79 as reserved word 232 tracing execution 173-174, 208, 217
PRINT and 104 ; (semicolon) and 112 trigonometric functions 37-38
constants 74-84 See also HTAB, VTAB TYPE MISMATCH message 241
converting 81-84, 216 TAN function 38, 217
dividing
input 90-91
tangent, calculating 38, 217
See also arc tangent
u
lowercase and 7 4 tape cassette unconditional branching 44-45, 201
null 75 See cassette tape UNDEF'D FUNCTION message 242
numeric value of 218 UNDEF'D STATEMENT message 242
IT) (Up-Arrow key) 17-18
Index 339
uppercase 3, 18 vector(s) words, reserved 232-233, 269-271
user-defined plotting, in shape tables 139-140 writing
functions 198, 200 reset 15 to cassette tape 296, 297
subroutines 165-166, 217 vertical lines, in low-resolution
USR function 165-166, 217 graphics 128, 218 X
utilities, system 162-168 VLIN statement 128, 218
utility strobe 119, 255 VTAB statement 113-114, 218 XDRAW statement 153-154, 219
See also HTAB, TAB animation with 154
V See also DRAW
VAL function 82-83, 218
w XPLOT 232
value(s) WAIT statement 166-168, 218 Y, Z
assigning 27-28 window(s)
variable(s) 22-26 cursor in 248-249 zero page 271-274
array 26, 70-74 text 19, 109-110, 163-164, 203
branching to 45 clearing 109, 247 •
clearing unused 171-172 HTAB and 112
index 50 setting 245-246
memory allocation and 269-271
numeric 11
real 23-24
resetting 8, 197, 208
string 11, 23-24, 25-26, 75
340 Index