Apple II Applesoft BASIC Programmer's Reference Manual - Volume 2
Apple II Applesoft BASIC Programmer's Reference Manual - Volume 2
This manual is copyrighted . All rights are reserved . This document may
not, in whole or part , be copied , photocopied , reprodu ced , translated or
reduced to any electronic medium or machine readable form without prior
consent , in writing , from Apple Computer , Inc .
The word Apple and the Apple logo are registered trademarks of
Apple Computer, Inc.
......
'-
"-
213
'- Appendices
Summary of App/esoft
Statements and Functions
ABS
Syntax: A B S (aexpr)
Example: ABS (- 2.77 )
ASC
Syntax: AS C (sexpr)
Example: ASC (" QUEST II )
Yields the ASCII code for the first character in the argument. The
example yields 8 1 (ASCII code for Q) . [4.2.5, C]
Assignment Statement
Syntax: [ LET] avar = aexpr
[LET] svar = sexpr
Example: LET A = 23.567
A$ = II HUMBUG II
CALL
Syntax: CAL L aexpr
Example: CALL -822
CHR$
Syntax: C H R $ (aexpr)
Example: CHR$ (65)
CLEAR
Syntax: CLEAR
Example: CLEAR
COLOR =
Syntax: COL 0 R = aexpr
Example: Co L oR= 12
CONT
Syntax: CON T
Example: CON T
cos
~
DATA
Syntax: D A T A [literal I string I real I integer]
[ { , [literal I string I real I integer] } ]
Example: D A T A J 0 H N S MI T H, " C 0 D E 32", 2 3 • L15 ,
-8
DEF FN
Syntax: DE F F N name (name) = aexpr
Example: DEF FN CUBE ()<) = )< * )< * )<
Defines a new function for use in the program. The example defines a
function that yields the cube of its argument. [2.4.3]
DEL
Syntax: DEL linenum , linenum
Example: DEL 2 3, 58
DIM
Syntax: DIM name[ 'X, I$] subscript [ { , name[ 'X, I$] subscript} ]
Example: DIM MARK (5 0 ,3), NAME$ (50)
Defines and allocates space for one or more arrays. The example de-
fines a two-dimensional real array MAR K, whose first subscri pt var-
ies from 0 to 50 and whose second varies from 0 to 3, and a string
array N A ME $ with one subscript that varies from 0 to 50. [4. 1.1]
END
Syntax: END
Example: END
FLASH
Syntax: FLASH
Example: FLASH
FN
Syntax: F N name (aexpr)
Example: FN CUBE (6)
FOR
Syntax: F D R name = aexpr TO aexpr [5 T E P aexpr]
Example: FOR J = 1 TO 1 0
FOR MARK = 0 TO 1 00 S T EP 5
FOR NUMBER = 20 T O - 20 S TEP - 2
Marks the beginning of a loop, identifies the index variable , and gives
the variable's starting and ending values and (optionally) the amount
by which it is to change (step) on each pass through the loop. The
first example begins a loop whose index variable J will take on all val-
ues from 1 to 1 0 , stepping by 1 ; the second begins a loop whose in-
dex variable MAR K will take on values from 0 to 1 0 0 , stepping by 5;
the third begins a loop whose index variable N U MB E R will take on
values from 20 to - 2 0, stepping by - 2 . [3.3.1]
FRE
Syntax: F R E (expr )
Example: FRE (0)
GET
Syntax: GET var
Example: GET ANSWER$
GOTO
Syntax: GOTO linenum
Example: GOTO 400
GR
Syntax: GR
Example: GR
HCOLOR =
Syntax: H COL 0 R = aexpr
Example: HCOLOR = 1
HGR
Syntax: HGR
Example: HGR
HIMEM:
Syntax: HIM EM: aexpr
Example: HI MEM: 32767
HLIN
Syntax: H LIN aexpr1 , aexpr2 AT aexpr3
Example: H LIN 1 0 , 2 0 AT 30
HOME
Syntax: HO ME
Example: HOM E
Clears all text from the text window and moves the cursor to the top-
left corner of the window. [5.2.4]
HTAB
Syntax: H T A 5 aexpr
Example: HTA5 23
Positions the cursor to a specified column of the text display. The ex-
ample moves the cursor to column 23. If you have the Apple lie 80-
Column Text Card, see the manual accompanying that product for
further information on using H T A 5. [5.2.4]
IF ...THEN
Syntax: I F expr THE N statement [ {: statement} ]
IF expr THEN [G OTO ]linenum
IF expr[THEN] GOTO linenum
Example: I F AGE < 18 THEN A 0: 5 = 1 :
c = 2 ~
Specifies the source for subsequent input. The example causes sub-
sequent input to be read from the device in expansion slot 2. [5 .1.1]
INPUT
Syntax: IN PUT [sexpr ;] var [ { , var} ]
Example: IN PUT A/,.
INPUT "TYPE AGE, THEN A COMMA,
THEN NAME " ; AGE, NAME$
Reads a line of input from the current input device. The first example
reads a value into variable A/'.; the second displays a prompting mes-
sage and then reads values into variables AGE and N A ME $ . [5.1.2]
INT
Syntax: I NT ( aexpr )
Example: I NT (98.6)
INT (-273.16)
Yields the integer part of the argument value . The examples yield 98
and - 27 LI, respectively. [2.4.1]
I Nl.'ERSE
Syntax: I NI.JERSE
Example: I NI.JERSE
LEFT$
Syntax: L EFT $ (sexpr, aexpr )
Example: LEFT$ (" AP PLESOFT " , 5 )
223
Summary of Applesoft Statements and Functions
LEN
-
......
LET
See "Assignment Statement," above.
LIST
Syntax: L IS T [linenum1] [ - linenum2]
LIS T [linenum1] [, linenum2]
Example: L IS T
LIS T 150
L IST 2 0 0-300
LIST 2 0 0 , 30 0
LOAD
Syntax: LO A D [name]
Example: LO A D
LOAD DE MO
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 DE MO. If you have one or more disk drives, see your DOS
manual for further information. [1 .2.6, M]
LOG
Syntax: LOG ( aexpr)
Example: LOG (2)
Sets the address of the lowest memory location available to the pro-
gram for variable storage. The example sets the beginning of variable
storage to 24578. [7.2.2]
MID$
Syntax: MID $ (sexpr, aexpr [ , aexpr] )
Example: MID $ ( " A NAP P LEA DAY", 4, 5)
MID$ ( " AN APPLE A DAY " , 4)
NEW
Syntax: NEW
Example: NEW
Clears the current program from memory and resets all variables and
internal control information to their initial states. [1.2.1]
Marks the end of a loop and causes the loop to be repeated for the
next value of the index variable , as specified in the correspond ing
FOR statement. The first example ends the most recently entered
loop; the second ends the loop whose index variable is IN D E){; the
third ends the pair of nested loops whose index variables are J and
I. [3.3.2]
NOTRACE
Syntax: NOTRACE
Example: NOTRACE
ON ...GOSUB
Syntax: 0 N aexpr GO SUB linenum [ { , linenum}]
Example: ON I D GOSUB 1 00 , 2 00 , 2 3 , 4 005 , 500
Chooses a subroutine to execute depending on the value of an
expression. The example transfers control to the subroutine begin-
ning at line 100,20 0,2 3 , 4005 , or 5 0 0 , depending on whether
the value of I D is 1, 2 , 3 , 4 , or 5 ; if I D has none of these values ,
execution continues with the next statement. [3.4.3]
ON ... GOTO
Syntax: 0 N aexpr GOT 0 linenum [ { , linenum} 1
Example: ON I D Go T o 1 00 , 20 0 , 23 , 4 005, 500
ONERR GO TO
Syntax: oNERR GoTo linenum
Example: ON ERR GoTo 500
PEEK
Syntax: PEE K ( aexpr )
Example: PEEK (37)
PLOT
Syntax: P L D T aexpr , aexpr
Example: PLD T 10 , 2 0
POKE
Syntax: PO K E aexpr , aexpr
Example: PoK E - 16302, 0
POP
Syntax: POP
Example: POP
Removes the most recent return address from the control stack,
causing the next RET URN statement to send control to the state-
ment following the second most recently executed GO 5 U B. [3.4.4]
Yields the current horizontal position of the cursor on the text display.
The argument is ignored, but must be a valid Applesoft expression .
[5.2.4]
PR#
Syntax: P R# aexpr
Example: P R# 1
PRINT
Syntax: P R I NT [ { expr [ ,I ;] }]
Example: P R I NT
I I. V
PRINT A$ , " )( = , 1\
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 $ , fol-
lowed at the next available tab position by the string ")( = ", fol-
lowed immediately by the value of variable )( . [5.2.2]
READ
Syntax: READ var [ { ,var} ]
Example: READ A, B'X., C$
RECALL
Syntax: RECALL name[ 'X. ]
Example: RECALL M){
Reads values into an array from a tape cassette. The example reads
values into array M){. [M]
RESTORE
Syntax: RESTORE
Example: RES TORE
RESUME
Syntax: RES U ME
Example: RESUME
RETURN
Syntax: RET URN
Example: RETURN
RIGHT$
Syntax: RIG H T $ ( sexpr , aexpr )
Example: R IGHT $ ("APPLES OF T", 4)
RND
Syntax: RN 0 ( aexpr )
Example: RND (1)
RUN
Syntax: RUN [Iinenum I name]
Example: RUN
RUN 500
RUN DEMO
SCALE =
Syntax: S CAL E = aexpr
Example: SCALE = 10
Yields the code for the color currently displayed at a designated posi-
tion 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 GN ( aexpr )
Example: SGN ( - 1 LlLI)
SHLOAD
Syntax: S H LOA D
Example: SHLOAD
SIN
Syntax: SIN ( aexpr )
Example: SIN (2)
L SPC
Syntax: S PC ( aexpr )
Example: S PC (8)
SPEED=
Syntax: S PEE D = aexpr
Example: SPEED = 50
Sets sets the rate at which text characters are sent to the display
screen or other input/output device. The slowest rate is 0; the fastest
is 255. [5.2.4]
Yields the positive square root of the argument ; the example yields
1 • Ll1 Ll2135G . [2.4.1)
STOP
Syntax: S TOP
Example: S TOP
STORE
Syntax: STORE name[ 'X. ]
Example: STORE M>(
----------------------------------------------------~
STR$
Syntax: S T R$ ( aexpr )
Example: STR$ (12.45)
TAB
Syntax: TAB (aexpr)
Example: TAB (23)
Positions the text cursor to a specified position on the output line dur-
ing execution of aPR I NT statement. The example moves the cursor
to column 23. [5.2.4]
Syntax: T E ){ T
Example: T E ){ T
TRACE
Syntax: TRACE
Example: TRACE
USR
Syntax: US R (aexpr)
Example: USR (3)
I.JAL
Syntax: 1.J A L ( sexpr )
Example: I.J A L (" - 3 + 7 E Lj" )
1.J TAB
Syntax: t.J TAB aexpr
Example: t.J TAB 1 5
Positions the cursor to a specified row of the text display. The exam -
ple moves the cursor to row 15. [5.2.4]
WAIT
Syntax: WA I T aexpr , aexpr [ , aexpr]
Example: WAIT 49347, 15
WAIT 49347, 15, 12
)<DRAW
Syntax: ;{D RAW aexpr [A T aexpr , aexpr]
Example: ;'WRAW 4 AT 50, 100
}{DRAW 4
Syntax Definitions
character
letter Idigit Ispchar Iquote Ispace
digit
o I 1 12 13 I a I 5 I G I 7 I 8 I 9
integer
[+ I - 1{digit}
Valid integers must be between - 327 G7 and + 327 G7 .
intvar (integer variable)
name 'X, [subscript]
letter
uppercase I lowercase
line
linenum [ {statement: } ] statement I RET URN I
linenum (line number)
digit [ {digit} 1
literal
[ {character} ]
lowercase
a I b I c g I h I i I j I k
1 I III I n r I 5 I t I u I I)
IAI I x I }'
name
uppercase [ {uppercase Idigit} ]
real
[+ I -] {digit} {. {digit} ] [ E [+ I - ] [digit [digit]]]
.- [+ - ][ {digit} ]
• [ {digit} ][ E [ + - ][ digit[digit]ll
The letter E in a real number stands for "times ten to the
power." Valid reals must be between - 1 E 3 8 and
+ 1 E38 .
Applesoft recognizes the following as reals and evaluates
them as zero:
+. - . .E + .E - .E
.E+ • E- + .E + + .E - - .E + - .E-
@ [ ] { } \
statement
See Appendix A for syntactic definitions of all Applesoft
statements.
string
" [{schar}] "
" [{schar}]
subscript
( aexpr [ { I aexpr} ] )
L I MI N I D I p I Q I R I 5 T I u I l.J I
wI \I
t\
I y I z
var (variable)
- avar l svar
Syntax Definitions
Syntax Definitions
ASCII Character Codes
32 20 ~IJ
33 21
34 22 II
35 23 #
36 24 $
37 25 'X.
38 26 IS:
38 27
40 28
41 28
42 2A
*
43 2B +
44 2C
45 2D
46 2E
47 2F /
48 30 0
48 31 1
50 32 2
51 33 3
52 34 4
53 35 5
54 36 6
55 37 7
56 38 8
57 39 9
58 3A
59 3B
60 3C <:
61 3D
62 3E >
63 3F ?
64 40 @
65 41 A
66 4 '"'"- B
67 43 C
68 44 D
69 45 E
70 46 F
71 47 G
72 48 H
73 49 I
74 4A J
75 4B K
76 4C L
77 4D M
'-
78 4E N
78 4F 0
80 50 P
81 51 Q
82 52 R
83 53 S
84 54 T
85 55 U
"-
86 56 1.J
87 57 W
'"'-
88 58 \I
1\
89 59 Y
~
90 5A "7
L.
91 5B [
--- 92 5C \
93 5D ]
84 5E
85 5F
86 60
87 61 a
98 62 b
99 63 c
100 6L1 d
101 65 e
102 66 f
103 67 9
lOll 68 h
105 69 i
106 6A j
107 65 f~
108 6C 1
109 6D ITI
110 6E n
111 6F 0
112 7{) p
113 71 "I
llL1 72 r
115 73 s
116 7L1 t
117 75 u
118 76 l)
119 77 1,,1
120 78 x
121 79 }'
122 7A z
123 75 {
12L1 7C
125 7D }
126 7E
127 7F I DELETE I
Reserved Words
Applesoft tokenizes these reserved words (converts them into one-
byte internal codes); see Section H.4 for a list of tokens. All other
characters in a program occupy one byte each of program storage.
Even if you don't embed reserved words in your variable names, they
can sometimes pop up unexpectedly and cause problems. For exam-
ple, the statement
is interpreted as
L ?){){ ERROR
where )-( >~ is the name of the particular error, as listed below.
where Y Y is the line number of the statement in which the error oc-
curred ; the Applesoft prompt character (J) and the cursor are dis-
played, and control of the system is returned to 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
CON T command (see Section 1.3.3) . An error in a deferred-execu-
tion statement is not detected until the statement is executed .
Errors associated with the Disk Operating System (DOS) will also
register at location 222; see the DOS manual for further information .
LET A ( 1, 1, 1) = Z
DIM A(Z,Z)
CAN'T CONTINUE
An attempt was made to continue a program with the CD N T com-
mand when no program exists in memory, or after an error, or after a
line has been changed , deleted from , or added to the program .
IF "ZZ" THEN
• DE F FN
• GE T
• INPUT '
• DNERR GD T O
• READ
• RE SUME
OI.IERFLOW [69]
-
. The result of an arithmetic calculation was too large to be repre-
sented in Applesoft's internal number format.
LET A (I) = 3
DIM A (100)
the RED I M'D A R RAY error will result. Another common cause of
the error is a program that loops back to a line before the DIM state-
ment, consequently executing it a second time.
This error message can prove useful if you wish to discover on what
program line an array was defined : just insert a DIM statementforthe
array in the first line, run the program, and the program will halt with a
RED I M'D A RRAY error when the original 0 I M statemer)! is
executed.
L
Peeks, Pokes, and Calls
PEE K function: see Section 7.1 .1 This appendix discusses some of the many special features of the
Apple lie that you can use in your Applesoft programs by means of
PO K E statement: see Section 7.1 .2
PEE K, PO K E, or CAL L statements. Notice that some of them dupli-
CAL L statement: see Section 7.1 .3 cate the effects of other Applesoft features.
soft switch: a location in memory that Many of these special addresses are soft switches with the property
produces some special effect whenever that any reference to them, whether a read (that is, aP E E K) or a
its contents are read or written
write (a P OK E) , invokes the feature associated with the address. For
instance, the example given here for switching from text to graphics
without clearing the graphics screen is
POKE -16304, 0
Screen Text
F.1
The special locations described in this section are used for control-
ling the display of text on the screen : setting the boundaries of the
text window within which characters are displayed and scrolled ,
clearing all text from all or part of the screen , scrolling text with in the
text window, and controlling the position of the cursor.
Screen Text
Setting the text window does not clear the remainder of the screen (for
HOME, HTAB, l)TAB statements: see which you can use HOM E) and does not move the cursor into the new
Section 5.2.4 text window (use HOM E again, or HTAB and l,J TAB).
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 will be moved by the same amount you move the left
edge. To protect your program and Applesoft, first reduce the window
width appropriately (see below) ; then change the left edge.
POKE 33t 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
a
and 0 (or 1 and 80 if you 're using the aD-Column Text Card) .
Warning
Make sure the right edge of the text window doesn't extend past the right
edge of the display screen . The window width shouldn 't be set greater
than 1I 0 (or 80) minus the current left edge of the wiildow. For example ,
if you've set the left edge of the window (see above) to 10, don't set the
window width greater than 30 (or 70 with the 80-Column Text Card).
Setting the window too wide will cause display text to be written outside
the usual memory area reserved for it, destroying parts of your program
or vital system information.
Warning
Do not set the window width to zero! The statement
POKE 33, 0
TAB function: see Section 5.2.4 If IN is less than 33 , the TAB function in aPR I NT statement may
cause characters to be displayed outside the text window.
Warning
Do not set the top edge of the window (T) lower than the bottom edge
(see below) .
POKE 35t B
Sets the bottom edge of the text window to the value specified by
expression B. This value should be between (> and 23 , where 2 3
represents the bottom line of the screen.
Warning
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 will
cause display text to be written outside the usual memory area reserved
for it, destroying parts of your program or vital system information.
Warning
Do not set the bottom edge of the window (5) higher than the top edge
(see above) .
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 typing
ITill F 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 typing
ITill E from the keyboard .
255
Screen Text
CALL -822
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 typing
Scrolling text on the screen I CONTROL I-J from the keyboard .
CALL -812
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 (38)
POSitioning the cursor Yields the current horizontal position of the cursor, which will be a
number between 0 and 39 (0 and 79, if you're using the aD-Column
Text Card) . 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 PO S function (see Section 5.2.4).
POKE 38t CH
Moves the cursor to the horizontal position specified by expression
C H, 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 0 and the current width of the window, with 0 representing
the leftmost column of the window. The effect is the same as that of
the H T A 5 statement (see Section 5.2.4) , but is not limited to 4 0
columns.
-'
Like H TAB, this statement can move the cursor beyond the right edge
of the text window, but only long enough to display one character.
256
Peeks, Pokes, and Calls
• Warning
Don't move the cursor past the right edge of the display screen! The cur-
sor position shouldn't be set greater than LI 0 (or 80) minus the current
left edge of the window. For example, if you 've set the left edge of the
L window (see above) to 10, don't set the cursor position greater than 30
(or 70 with the aD-Column Text Card) . 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, which will be a num-
ber 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 0
represents the top line of the screen, 23 the bottom line.
POKE 37 t Cl.J
Like V TAB, this statement can move the cursor beyond the bottom
edge of the text window, but all subsequent text sent to the display
screen will then appear on that same line.
... Warning
Don't move the cursor past the bottom edge of the display screen! Set-
ting the cursor position beyond line 23 will cause display text to be writ-
ten outside the usual memory area reserved for it, destroying parts of
your program or vital system information .
PEEK (-18384)
......-
Reading the keyboard Reads the last character typed from the keyboard. If the high-order
bit of this location is 1 (P E E K yields a result > 1 27) , then a new
character has been typed since the last PO KEto address - 1 6368
(see below); subtracting 1 2 8 from the value received gives the
ASCII code for the character typed . If the high-order bit is 0 (P E E K
yields a result > = 12 7), then no new character has been typed
since the last POK E to - 16368.
POKE -18388t 0
Clears the high-order bit of location - 1638 a (see above) to prepare -.J
For more information ... For further information on these and other soft switches in the Apple lie's
memory, see the Apple I/e Reference Manual.
POKE -18304t 0
Displaying graphics 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 graph-
ics, taken from page 1 or 2, and full-screen graphics or mixed text and
graphics.
Graphics
POKE -16303t 0
Displaying text Switches the display from any form of grarhics 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 T E){ T statement also switches to text display, but in addition se-
lects 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 -16302t 0
Full-screen graphics 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 cur-
rently being displayed, there is no visible effect.
POKE -16301 t 0
Mixed text and graphics Switches the display from full-screen graphics to mixed text and
graphics, with four lines of text at the bottom of the screen. Depend-
ing on the settings of the other soft switches, the upper portion of the
screen may show low- or high-resolution graphics, taken from either
page 1 or page 2. The text displayed in the bottom four lines will be
taken from the same page number as the graphics in the upper part
of the screen . If full-screen text is currently being displayed, there is
no visible effect.
POKE -16300t 0
Displaying page 1 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 graph-
ics 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.
Displaying page 2 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 graph-
ics 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 -lG288t (I
Low-resolution graphics Switches from high- to low-resolution graphics, without clearing the
screen. Depending on the settings of the other soft switches, the re-
sulting display may be taken from low-resolution page 1 or page 2,
and may be either full-screen low-resolution graphics or mixed with
four lines of text from the same low-resolution page. If full-screen text
is currently being displayed, there is no visible effect.
POKE -lG287t 0
High-resolution graphics Switches from low- to high-resolution graphics, without clearing the
screen. Depending on the settings of the other soft switches, the re-
sulting 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 -1888
Clearing the graphics display Clears low-resolution page 1 to black if displaying low-resolution
graphics, or to black-on-white at-signs (@) if displaying text. If display-
ing high-resolution graphics, or text or low-resolution graphics from
page 2, there is no visible effect.
CALL -1884
Clears the upper 40 rows of low-resolution page 1 to black if display-
ing 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.
Graphics 261
CALL -3086
Clears the current high-resolution page to black. (Applesoft remem-
bers which page you used last, regardless of the switch settings.)
CALL -3082
Clears the current high-resolution page to the color most recently
used in an H P LOT statement. (Applesoft remembers which page
you used last, regardless of the switch settings.)
The annunciators are four pins of the hand control connector that can
each be set to either of two states (on or off). The utility strobe is another
pin of the connector that is normally at + 5 volts but can be triggered to
drop to zero volts for one-half microsecond. These features are typically
used to control devices such as lamps and relays connected to the com-
puter through the hand control connector. See the Apple lie Reference
Manual for further information.
PEEK (-16287)
Reading the hand control buttons Reads the button on hand control 0; yields a result > 127 if the but-
ton is being pressed, < = 127 if it is not. The [ 0 PEN - APPLE Ikey on
the Apple lie keyboard is equivalent to this button and can be read in
the same way.
PEEK (-16286)
Reads the button on hand control 1 ; yields a result > 1 27 if the but-
ton is being pressed, < = 127 if it is not. The [ SOLI D-APPLE Ikey on
the Apple lie keyboard is equivalent to this button and can be read in
the same way.
Notice that, although there are provisions for connecting four hand con-
trols (numbered 0 to 3) to the computer, there is no way to read the but-
ton on hand control 3.
POKE -16295t 0
Controlling the annunciators Turns on annunciator output 0 (hand control connector, pin 15).
POKE -16296t 0
Turns off annunciator output 0 (hand control connector, pin 15).
POKE -16293t 0
Turns on annunciator output 1 (hand control connector, pin 14).
POKE -16294t 0
Turns off annunciator output 1 (hand control connector, pin 14) .
POKE -16291 t 0
Turns on annunciator output 2 (hand control connector, pin 13).
POKE -16292t 0
Turns off annunciator output 2 (hand control connector, pin 13).
POKE -16289t 0
Turns on annunciator output 3 (hand control connector, pin 12).
L POKE -16290t 0
Turns off annunciator output 3 (hand control connector, pin 12).
The utility strobe should always be controlled with PEE K, not with
PO K E. Using PO K E triggers the strobe twice instead of once. See the
Apple lie Reference Manual for further information.
PEEK (-16336)
Controlling the speaker Produces a single click from the built-in speaker; can be used in var-
ious combinations and frequencies to produce musical tones and
other sounds.
PEEK (-16352)
Produces a single click on a cassette recording or on an audio ampli-
fier connected to the cassette output jack via the amplifier's auxiliary
input jack; can be used in various combinations and frequencies to
produce musical tones and other sounds. See Appendix M for further
information on using a cassette recorder.
Error Handling
F.5
This section describes the special locations associated with Apple-
soft's error handling mechanism . They can be used by user-supplied
ONE R R GOT 0 statement: see Sec- error-handling routines established with the 0 N ERR GOT 0
tion 3.5.1 statement. See Section 3.5 and Appendix E for further information.
------------------------------------------------~-
PEEK (216)
Yields a result > 1 27 if an error-handling routine has been estab-
lished with the 0 N ERR GO T 0 statement, < = 1 2 7 if normal error
handling is in effect.
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 (DOS) will also regis-
ter at location 222; see the DOS manual for further information.
CALL -3288
Clearing the control stack Clears from Applesoft's internal control stack information placed
there when an error-handling routine was called . Should be used be-
fore exiting from any error-handling routine with aGO T 0 instead of a
RES U ME statement.
CALL 54815
Empties the internal control stack of all control information, without
affecting the contents of any variables.
The information in this appendix can help you write programs that run
faster or use less memory space. Section G.1, " Saving Space," gives
L_----__
tips you can follow if you need to conserve memory space. Section
G.2, " Saving Time," suggests ways to speed up program execution .
Saving Space
G.1
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 state-
ments, combining several statements onto a single program line, and
eliminating optional semicolons in P R I NT lists. Here are some tips
for programmers who prefer to do the work themselves :
When combining statements into fewer lines, remember that when the
condition in an IF ... THE N 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.
Take care not to delete REM lines that are referred to by other lines. For
example, if your program includes the lines
and you delete line 300, the program will halt with an UNO E FlO
STATEMENT error.
Like programs with many statements on each line, those without de-
tailed 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.
PI = 3.14159
10 LE T A$ "WELL, "
20 LET B$ " MARSHA, "
30 LET C$ "IT LOOKS LIKE"
40 LET C = 10
50 PRINT A$ B$ C$ "FRED IS" C" HOURS
LATE!"
10 LET A = 5
20 LET B = 10
30 LET C 1.0 = 15
40 LET D 10
50 PRINT A B CO lo D
Saving Space
Applesoft interprets line 50 as saying " display the value of inte-
ger variable ABC /." followed by the value of real variable D," and
will display
010
Since variable ABC '1" hasn't been assigned a value , its value is O.
• If a quoted string is the last item in the last statement of a line, the
closing quotation mark may be omitted , saving one byte :
This last technique should be used with caution : bad things can happen
if the omitted quotation mark comes somewhere other than at the end of
aline:
Saving Time
G.2
Utility programs called compilers are now available that convert Ap-
plesoft programs to a form in which they run far faster than normally.
However, a compiled program can take as much as 50% more space
than a non-compiled one. The hints listed below 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 of integer
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 subrou-
tines , loops, and other program segments that are executed
repeatedly.
5A = 0:B = A:C = B
will place A first in the variable table, B second , and C third (as-
suming this line is the first executed in the program). When these
variables are referred to later in the program, Applesoft will have
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 vari-
ables that your program refers to most often to be located as
early as possible in the variable table.
it scans the entire program from the beginning until it finds the
desired line number ( 1 00, in this example) . So you can speed
things up by placing frequently-referenced lines as early in the
program as possible.
Saving Time
272
Hints for Program Efficiency
Implementation Details
....
start of variables
$0069-$006A(LOMEM:)
105-106 SIMPLE
VARIABLES
start of arrays ~
$0066-$0 0 6C
107-108
ARRAYS
end of variables
$0060-$0 0 6E
109-110
FREE SPACE
start of strings ~
$ 0 06F-$0 0 7 0
111 - 112
STRINGS
MEM :)
end of strings (H I
$ 0 073-$0074
115-11 6 ~
Real arrays use a minimum of twelve bytes: two bytes for the array
name, two for the size of the array in bytes, one for the number of di-
mensions, two for each dimension, and five for each element of the
array. Integer array variables use only two bytes for each element.
String array variables use three bytes for each element: one for the
length of the string and two for a painter to its contents. Multidimen-
sional arrays are stored with the first subscript varying fastest.
Array Variables
where FIR S TAD D Rand SEC N DAD D R are the addresses of the
two bytes of the pOinter itself.
Table H-2 Applesoft Zero Page Usage
Location(s) Used for
$0051 $00C8 Character input routine. Applesoft calls here every time it
177 - 200 wants another character.
Implementation Details
Table H-2 continued
-
Location(s) Used for
Keyword Tokens
H.4
Applesoft tokenizes all its key words ; that is, it converts them to one-
byte codes called tokens to save memory space. Table H-3 gives a
list of the tokens representing the various keywords.
'-
281
Implementation Details
Table H-3 continued
Hex Dec Keyword Hex Dec Keyword
$DA 218 SQR $E3 227 LEN
$DEJ 219 RND $Ea 228 STR$
$DC 220 LDG $E5 229 1.'AL
$DD 221 E~{ P $E6 230 ASC
$DE 222 COS $E7 231 CHR$
$DF 223 SIN $E8 232 LEFT$
$EO 22a TAN $E9 233 RI GHT$
$El 225 ATN $EA 23a MID$
$E2 226 PEEK
PRINT 1.23456787654321
-you type this from the
keyboard
will display
on the screen.
All arithmetic done on reals Integers are always converted to real form before being used in arith-
metic calculations, and the results are converted back to integer form
when assigned to an integer variable. Conversion from real to integer
truncate: to convert a real number to the form is by truncation to the next lowest integer, not by rounding to tbe
next lowest integer nearest integer.
Table 1-1 shows examples of the formats used for displaying and
printing numbers.
Table 1-1 Number Formats
Number Output Format
+1
- 1 - 1
6523 6523
- 23.460 - 23.46
45 .72*10 ' 5 45720 00
1 * 10 "' 20 1 E + 20
- 12.34567896 * 10 ,', 10 - 1. 23 45G 79 E +1 1
1000000000 1 E + 09
999999999 999999999
y
only one digit to print after all trailing zeros are suppressed, no deci-
mal point is shown . The letter E (for "exponent") is always followed
by a sign and a two-digit exponent. The value of a number repre-
sented in this form is the number before the E times 10 raised to the
each )( is a digit power after the E. For example,
The figures and tables below 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 the Apple lie Owner's Manual and the Apple lie Applesoft Tutorial.
If you have the Apple lie aO-Column Text Card installed in your
computer, additional escape-mode features are available ; see the
aD-Column Text Card Manual.
B A
c
Figure J-2 Long-range Cursor Moves
I
J K
I LEFT - ARROW I Moves cursor left one position ; remains in escape mode
I RIGHT - ARROW I Moves cursor rig ht one position ; remains in escape mode
I DOWN - ARROW I Moves cursor down one line ; remains in escape mode
'"'-
The following chart summarizes the differences in the Apple lie's be-
havior with and without the Apple lie aO-Column Text Card installed.
Notice that even 40-column display behaves somewhat differently
with the aO-Column Text Card installed and active than without it. See
Table K-1 40/80-Column Display the aO-Column Text Card Manual for further information .
Differences
Card Active: Plus-sign Upper- and Clears text Not available Not available Not available
"- SO-Column cursor; lowercase window for second for second
Display additional to white; DO NOT USE 40 columns 40 columns ; use
escape-mode characters POKE 36 t }<>~
features displayed
available in black
INT
To switch from Integer BASIC to Applesoft, type
FP
F P stands for "floating-point," the name for the internal format used by
languages like Applesoft to represent real numbers.
ATN
CHR$ COS
DATA DEF FN DRAW
FLASH FN FRE
GET
HCDLOR = HGR HGR2 HIMEM: HOME HPLOT
I NT I NI.JERSE
LEFT$ LOG LOMEM:
MID$
NORMAL
ON ... GOSUB ON ... GOTO ONERR GOTO
POS
READ RECALL RESTORE RESUME R I GHH ROT =
SCALE = SHLOAD SI N SPC SPEED = SQR STOP STORE STR$
TAN
USR
WAIT
)-( DRAW
Table L-2lists Integer BASIC statements and functions that are not
Table L-2 Integer BASIC Features Not available in Applesoft.
Available in Applesoft
AUTO
DSP
MAN
MOD
CLEA R CLR
CONT CON
HTAB T AB
HOME CA LL - 9 36
POK E 50, 127
F L ASH PO KE 50,63
<> or >< #
Other Differences
L.2
As the name implies, the only numbers Integer BASIC can deal with
are integers (whole numbers) . Real variables and constants (num-
bers with decimal pOints or exponents) are available in Applesoft but
not in Integer BASIC.
In Applesoft, only the first two characters in a variable name are sig-
nificant (for example, GOOD and GO U GE are recognized as the
same variable) . In Integer BASIC, all characters in a variable name
are significant.
Other Differences
Applesoft arrays may be multidimensional ; Integer BASIC arrays are
limited to one dimension. There are no string arrays in Integer
BASIC.
DIM A$ (It J )
DIM A$(J)
A$ (I)
A$ (It J)
Convert A$ ( I )
to MID $ ( A$ t I t 1)
Convert A$ ( I t J)
to MID $ ( A$ t I t J - I + 1)
Convert A$ ( I ) = )($
to A$ = LEFT$(A$, I 1) + )( $ +
MID$ (A$ , I + 1)
Convert A$ ( I , J ) = ){$
to A$ LEFT$(A$, I - 1) + )($ +
MID$(A$ , J + 1)
LET B = C = 0
C o B C
or
B 0: C = (>
• 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
of the conditions doesn't hold, the system may hang indefinitely. Only
[ CONTRO L 1-[ RESET I: see Section 1.3.2 I CONTROL 1-[ RESET Ican interrupt a tape operation; only God can make
a tree.
SA') E writes a program to tape The SA I.J E command writes the Applesoft program currently in
memory onto a tape cassette . 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 SA I.J E command is executed. Beeps
signal the start and end of the recording.
Occasionally a tape recorder will 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 (usu-
ally labeled "monitor" on the tape recorder) when recording . Such a
ground loop causes no trouble when reading a tape.
L a A 0 reads a program from tape The LOA D command reads an Applesoft program into memory from
a tape cassette. No prompting message or signal of any kind is given ;
the tape recorder must already be turned on and set to "play" at the
time the LOA D command is executed. A beep signals when the be-
ginning of information is detected on the tape; a second beep is
sounded when the program has been successfully loaded.
If your system is equipped with a disk drive and you have the Disk Oper-
ating System (DOS) loaded and running, a LOA 0 command with a
name following the keyword LOA 0 will read a program from a disk
under that file name. See Section 1.2.6 and your DOS manual for more
information.
5 TOR E writes an array to tape The S TOR E statement writes the contents of an integer or real array
onto a tape cassette. The name of the array (M >( in the example
above) follows the keyword S TOR E, without a subscript. No prompt-
ing message or signal of any kind is given; the tape recorder must
already be turned on and set to "record" at the time the S TOR E
statement is executed. Beeps signal the start and end of the
recording .
R E CAL L reads an array from tape The R E CAL L statement reads information into an integer or real ar-
ray from a tape cassette. The name of the array (M >( in the example
above) follows the keyword R E CAL L, without a subscript. The des-
ignated array must have been previously defined in a DI Mstatement
in the program issuing the RE CAL L .
The name of the array read with RECAL L need not be the same name
used in the S TOR E statement that wrote the information onto the tape.
However, the dimensions of the array being read should be the same as
those of the array originally written. For example, if the tape was written
by the statement
STORE A
RECALL B
DIM B (5, 5, 5)
If the dimensions of the two arrays differ, RECAL L may scramble the in-
formation read into array B, or the program may halt with the message
5 H LOA 0 reads a shape table from The S H LOA D (for "shape load") statement reads a shape table into
tape memory from a tape cassette. The shape table is loaded just below
the current setting of HIM EM: (see Section 7.2.1, "The HI MEM:
Statement") and HIM EM: is reset to just below the shape table to
protect it.
shape tables: see Section 6.3 See Section 6.3 for extensive information on shape tables.
304
Complete Listing of the Postage Rates Program
3020 IF W > 10 THEN 3160
- go to line 3 1 60 for weights
greater than 10 pounds
(ounce weights converted to
pou nds in consistency subrou-
tine starting at line 1200 0)
3025 REM
PRIORITY RATES TO 10 POUNDS
3030 IF W <: = 1 THEN T = 2.24
30LlO IF W > 1 AND W <: = 1.5 THEN T =
2 . 30 - rates in half-pound increments
3050 IF W >- 1.5 AND W <== 2 THEN T
2.5L1
3060 IF W ....... 2 AND W <= 2.5 THEN T
2.78
3070 IF W >- 2 . 5 AND W -:: = 3 THEN T
3.01
3072 IF W ..":. 3 AND W -:: = 3.5 THEN T
3.25
3078 IF W :::- 3 .5 AND W <= LI THEN T
3.Ll8
3080 IF W > LI AND W <= LI.5 THEN T
3.73
3080 IF W ....:. LI.5 AND W <= 5 THEN T
3.87
3100 IF W ....... 5 AND W <= 6 THEN T LI.LILI
"- - rates by the pound now!
3110 IF W > 6 AND W ( = 7 THEN T LI.82
3120 I F W > 7 AND W <= 8 THEN T 5.38
3130 IF W ..,,:' 8 AND W <= 8 THEN T 5.87
IF W > 8 THEN T = 6.35
31 L1 0
3150 GO TO 32L10 - branch to RET URN statement
3160 REM
PRIO RI TY RATES FOR ol,JER 10
POUNDS
3170 T1 = INT ( W / 5 - 1 )
3.8 7 * 2.38 +
- first 5 pounds cost $3.97; each
... 3180 WI = W - INT ( W / 5 )
added 5 pounds cost $2.38
5
*
- how many odd pounds are
there (pounds that are not
multiples of 5 and must be
charged at a special rate)?
3 180 IF W1 1 THEN Try"- .Ll7
3200 IF W1 2 THEN T2 = .85
AND : A logical operator that produces a true resu lt if both of its oper-
ands are true , a false result if either or both of its operands are false ;
compare OR , NO T .
Apple lie BO-Column Text Card: A peripheral card made and sold by
Apple Computer that plugs into the Apple lie's auxiliary slot and con-
verts the computer's display of text from 40- to aO-column width.
auxiliary slot: The special expansion slot inside the Apple lie used
for the Apple aO-Column Text Card or Extended aO-Column Text
Card.
back panel: The rear face of the Apple lie computer, which includes
the power switch, the power connector, and connectors for a video
display device, a cassette tape recorder, and other peripheral
devices.
bit bucket: The final resting place of all information; see write-only
memory.
Disk II drive: A model of disk drive made and sold by Apple Com-
puter for use with the Apple lie computer; uses 5-1 14-inch flexible
("floppy") disks.
display color: The color currently being used to draw high- or low-
resolution graphics on the display screen .
ending value: The value against which the index variable is tested
after each pass through a loop, to determine when to stop repeating
the loop.
infinite loop: A section of a program that will repeat the same se-
quence of actions indefinitely.
319
Glossary of Technical Terms
K: Two to the tenth power, or 1024 (from the Greek root kilo, meaning
one thousand); for example, 64K equals 64 times 1024, or 65,536.
keyboard: The set of keys built into the Apple lie computer, similar to
a typewriter keyboard, for typing information to the computer.
Monitor program: A system program built into the Apple lie in firm-
ware , used for directly inspecting or changing the contents of main
memory and for operating the computer at the machine-language
level.
nested loop: A loop contained within the body of another loop and
executed repeatedly during each pass through the containing loop.
NOT: A unary logical operator that produces a true result if its oper-
and is false, a false result if its operand is true; compare AND, DR.
queue: A list in which entries are added at one end and removed at
the other, causing entries to be removed in FIFO (first-in-first-out) or-
der; compare stack.
run: (1) To execute a program . (2) To load a program into main mem-
ory from a peripheral storage medium , such as a disk, and execute it.
soft switch: A means of changing some feature of the Apple lie from
within a program ; specifically, a location in memory that produces
some special effect whenever its contents are read or written .
stack: A list in which entries are added or removed at one end only
(the top of the stack) , causing them to be removed in LIFO (Iast-in-
first-out) order; compare queue.
starting value: The value assigned to the index variable on the first
pass through a loop.
327
Glossary of Technical Terms
strobe: (1) An event, such as a change in a signal , that triggers some
action . (2) A signal whose change is used to trigger some action .
text window: An area on the Apple lie's display screen within which
text is displayed and scrolled.
A B
ABS function 38,215 backslash character (\ ) 4, 18
absolute value 38, 215 BAD SUBSCR I PT error 79, 248
addition 32, 36, 86 bell character ( [ CONTROL [ - G) 130
American National Standards BLOAD command 158
Institute (ANSI) 3 body of loop 55
American Standard Code for booting 96, 112
Information Interchange, see branch 49ft, 220
ASCii conditional 51
ampersand character (&) 246 unconditional 50, 220
AND 35, 175 built-in arithmetic functions 38ft
animation 150
annunciators 131 , 262, 263 C
ANSI : see American National CALL statement 71 , 136, 216, 249,
Standards Institute 253ft,281,294
Apple lie 80-Column Text Card, see CAN ' T CONT I NUE error 248
80-Column Text Card [CAPS LOCK \ key 4
arc tangent 41 , 216 caret( " ) 31
argument of functions 37, 38, 125, cassette input 110
173,179 cassette output 131 , 264
argument variable 44 Celsius 44
arithmetic functions 38 character codes 82
arithmetic operators 31 CHR$ function 91 , 216
array(s) 26, 29, 77ft, 217, 228, 248, CLEAR command 9, 30, 129, 216,
249, 268, 275ff, 293ft, 298 294
dimensions 79, 80 colon (:) 5, 98ft, 105, 106, 177, 192,
elements 29, 77, 269 246, 267, 296, 301
names 29, 77 color, see display color
storage 179 COLOR= statement 137, 216
variables 275ft comma ( .) 98ft, 105, 113, 114, 115
arrow keys 18,20 commands , see names of
ASC function 215 commands
ASCII (American Standard Code for concatenation 83,84,100,251 ,
Information Interchange) 19,82, 295
215, 241ft,258 conditional branch 51
assignment statement 30, 215, constants 268
224,251 , 296 CONT command 16, 17, 73, 216,
asterisk ( *) 32 247,248
ATNfunction 41,216 control characters 100, 101,241
auto-repeat 19, 20
Index 331
ICONTROL I key 15, 16, 18,241 E
-@ 98, 107
e 42
-5 176, 177, 181
editing 287-288
-c 15ft, 50, 58 , 69, 72, Eighty-Column Text Card 4, 112,
98, 107, 159, 180, 216
114,115, 119, 124, 125, 127222
-G 130 254, 287ff ' ,
-H 100,107
END statement 17, 73, 216, 218,
-J (line feed character)
251,269, 294
192, 193, 216, 301
equal sign (=) 30, 34, 44, 129,1 37,
-M 100, 107
145, 163, 246
- [RESET I 13-17, 96, 112,
equal to (=) 34
161 , 162, 166, 171
error
-5 15
codes 68, 69, 247ft
-}( 18, 100, 107
messages 247ft
control
error handling routines 67ff, 229,
stack 10, 62ff, 71 , 227, 265
247, 264
statements 49ft
restoring normal 71
COS function 40,217
escape mode 19, 287
cosine 40, 217
crossed loops 60
IT.§£] key 20, 242
- @ 20, 255
current input device 104, 223
- A 20
current output device 10 113 224
228 ' , , -B 20
-C 20
cursor 4, 18ft, 97, 113, 115, 119ft,
- 0 20
220ft, 232, 234, 253, 254
- E 20
cursor control 287-288
- F 20, 255
D -1 19, 20
- J 19, 20
DATA statement 103, 105, 108, -K 19,20
217, 228, 229, 250 -M 19, 20
debugging 11,180 exclusive-or 175
DEF FN statement 44 177 217 execution of program 16
249 ' , ,
D( P function 42, 218
deferred execution 4, 5, 9, 247 expansion slot 96, 111
degrees 44 exponential 42, 218
DEL command 6, 7, 217
exponentiation 32
I DELETE I key 7 expressions 31ff
DIM statement 79, 217, 251 293 D(TRA I GNDRED message 99
295, 298 ' ,
105 '
disk 12ft, 112, 156, 230
Disk Operating System (DOS) 12 F
14, 16, 105, 157, 176 265 298 '
Fahrenheit 44
display color 137ft, 160 21'6 220ff false 33ft
231 ' , ,
FILE NOT FOUND error 14
display screen 111 FLASH statement 127 128 218
division 32 226 ' , ,
DIl.JISION BY ZERO error 248 floating-point accumulator 173
dollar
259sign ($) 26 ' 29 , 82 , 88 , 251 , F N keyword 45, 219
FOR statement 55ft, 219, 225, 271
DOS (see Disk Operating System) FORMULA TOO COMPLD( error
double quotation marks (") 28, 81 248
99 , 102, 270 ' F P command 291
[ DOWN-ARROW I key 18, 19,241 fractions 33
DRAW statement 151 , 155,156, FRE function 178,220
160,161 , 162, 163, 164218230 free space 275
231 ' , ,
332 Index
full-screen graphics 136, 138, 143, H
144, 146, 221 , 260
function names 44 hand control 109, 262
functions 37ff, 173, 177, 229 hand control connector 109, 131 ,
argument of 37, 38, 125, 173, 179 262, 263
built-in arithmetic 38 HCOLO R= statement 145, 160, 220
HGR statement 143, 145, 149, 161 ,
call 37, 38, 45
names 44 162, 220, 258, 259
HGR2 statement 144, 145, 149,
user-defined 44-45, 217
ABS 38, 215 161 , 162, 221 , 259
ASC 215 high-resolution graphics 136, 140ft,
ATN 41 , 216 150, 176ft, 218, 220ft, 230, 261
CHR$ 216 HI MEM: statement 149, 156, 165,
COS 40, 217 176, 179, 221 , 250, 275, 299
E)-( P 42, 218 HL I N statement 139, 221
FRE 178, 219 HOM E statement 221 , 254
I NT 39, 223
HPLOTstatement 146, 161 , 218,
LEFH 100,223, 249 222, 262
LEN 224 HTAB statement 120, 122, 126,
LET 215 181 , 222, 254, 256
LOG 42, 224, 249 Humpty Dumpty 19
MI 0$ 100, 225, 249
PEEK 130, 131 , 177, 178, 180,
I
247, 249, 253ft IF • • • THE N statement 33, 36, 52 ,
POL 109, 227 222 , 248 , 251 , 26~294
POS 125, 228 ILLEGAL 0 I RECT error 249
R I GHH 100, 229, 249 I LLEGAL QUANT I TY error 40,
RNO 43, 229 42, 52, 66, 86ft, 92, 97, 109, 112,
S CRN 141 , 231 121ft 129, 138ff, 146, 147, 161ft,
SGN 39 , 231 170, 171 , 175ft, 249
SIN 40, 231 immediate execution 4, 7, 9, 257
SPC 113, 120-121 , 231 , 249 I N# statement 96, 223
SQR 40, 232,249 index variable 55ft, 219 , 225, 271
STR$ 232 infinite loop 58
TAB 113, 120, 121 , 123, 126, input 95, 223
181 , 232, 233, 249, 254 numeric 100
TAN 4, 233 Input Anything Routine 102
USR 172, 233 IN PUT statement 16, 17, 97,
I,J AL 102,105,233 102, 223, 249 , 294
input/output 93ft
G string 99
I NT function 39, 223, 291
GAME I/O connector 109
GET statement 16, 19, 104, 220, integer
249 constants 270
GOSUB statement 61ff, 220, 227, part 39 , 223
229, 251 , 293 variables 26, 27, 44, 58 , 270,
GOT 0 statement 50 , 53 , 64, 71 , 275ft
220, 251 , 265, 293 Integer BASIC 260, 291
I NI,JER SE statement 126, 128,
GR statement 136, 140, 220, 258,
259, 261 223, 226
graphics 119, 135ft, 258
greater than ( » 34
J
greater than or equal to ( > = or = )- ) J MP (Jump) instruction 173, 233
34 J SR (Jump to Subroutine)
ground loop 297 instruction 173, 174, 246
Index 333
K nested subroutines 62
NEW command 9, 30, 150, 177, 225
keyboard 96, 258 NE )-(T statement 55ft, 225, 271 ,
keyword tokens 280ff 294
keywords 4 NE )-(T WI THDU T FOR error 10,
60, 249
L NORMAL statement 126, 128, 226
LEFH function 86, 100, 223, 249 NOT 35, 54
I LEFT - ARROW I key 18, 19, 100, not equal to « >or ><) 34
241 NOT RAC E command 181 , 226
LEN function 83,85, 224 null character (I CONT ROL I- @) 98,
LET statement 215, 224 100, 101 , 105
less than « ) 34 null string 9, 12, 28, 30, 81, 82, 88,
less than or equal to « = or = <) 34 9~98 , 100, 106, 251 , 294
line feed character (I CONTROL I- J) numberformats 117
192, 193,216, 255 numbersign(#) 96, 111 , 180, 246
line numbers 5ft, 50, 51 , 64, 65, 70, numeric constants 117, 283
180,220, 226, 232, 233, 251 , 265, numeric input 100
267, 293, 294
LIS T Command 7, 10, 224 o
L OAD Command 14, 110,224,298 ON ••• Go SUB statement 65, 226,
LOG function 42, 224, 249 249
logarithm, natural 42, 224 ON • •• GoTo statement 51 , 226,
logical operators 35, 54 249
logical values 33, 36, 54 on-screen edit 17
LoMEM: statement 177,225, 250 oNERR GoTo statement 68, 72,
loops 10, 55ft, 219, 225, 250, 270, 226 , 229 , 24~239 , 264 , 265
296 I OPEN-APPLE I key 110, 262
body 55 operators 31ff
crossed 60 arithmetic 30
nested 59 logical 35, 54
low-resolution graphics 135, 216, precedence of 36
220,221,231,234, 258, 261 relational 33, 54
OR 34, 54
M OUT OF DATA error 106, 250
machine language 172, 176, 177, OUT OF MEMOR Y error 60, 64,
179, 216,221 , 233, 246 177, 178, 250, 299
mask 174 output 111
MAT functions 296 o t}ERFLoWerror 90, 91 , 250
memory allocation 25, 275
memory management 176 p
MI D$ function 87, 100, 225, 249 parentheses 37, 250, 276
minus sign (-) 36,105 POL function 109, 227
mixed graphics and text 119, 136, PEE K function 68, 70, 110, 130,
138, 140, 141 , 143, 146, 220, 260 131 , 170, 177, 178, 180, 227, 247,
Monitor program 16, 72, 155ft, 172, 249, 253ft, 294
173, 176, 177, 181 percent character (,1.,) 26, 28
multidimensional array 80 period (.) 105
multiple input 98 PLOT statement 138, 227
multiple statements per line 5 plotting vector 150ft
multiplication 32 plus sign ( + ) 36, 84, 105, 295
point of call 61 , 64
N pOinter 275
natural logarithm 42, 224
nested loops 59
Index
POKE statement 71 , 72, 129ff, 136, I RETURN I key 4, 6, 10, 13, 16, 18,
143,149, 155, 156, 159, 170ft, 100, 104, 158, 165, 219, 241 , 293
227, 249, 253ff, 294 I NPUT statement use 97, 98
POP statement 66, 227 RETURN statement 61ff, 220, 227,
PO S function 125, 228 251
pound sign (#) 96 RETURN WI TH OUT GOSU5 error 64,
PR# statement 10, 111 , 228 67, 251
precedence 36 right bracket U) 4, 16, 119, 247
PRINT statement 105, 113ft, 120, RIGHT \ function 100, 229, 249
121 , 223,226, 228, 231 , 232, 254, I RI GHT-ARROW I key 18, 19, 241
267 RND function 43, 229
TAB used in 121ff ROT = statement 160, 164, 230
printer 10, 111 rotation 230
program 275 rounding 39
execution 16 RTS (Return From Subroutine) 174
layout 189 RU N Command 12, 14, 30, 108,
lines 3 145, 150, 230, 294
planning 185
specification 185 S
prompt character ( ] ) 4, 16, 119, SAI.l E Command 13, 131 , 230, 297
247 scale factor 230
prompting message 97, 294 SCALE = statement 160, 163, 164,
pure cursor moves 19 230
scientific notation 43, 91 , 118, 283
Q SCR Nfunction 141 , 231
question mark (?) 97, 116, 294 scrolling 253
seeding 43
R semicolon ( j ) 113ft, 122, 267, 269
radians 40, 41 , 44 SG N function 39, 231
RAM (random-access memory) shape definition 150
176, 179 shapetable(s) 150ft, 230, 231 , 234,
random numbers 43, 229 299
READ statement 105, 108, 207, index 153
217, 129, 250 loading 154ft
real variables 25, 27, 44, 58, 270, SHLOAD statement 110, 156, 158,
275-277 165, 231 , 299
RECA L L statement 110, 298 sign of a number 39, 231
RED I M ' D ARRA Y error 79, 250 simple variables 275- 277
REENTER message 99, 100 SIN function 40, 231
relational operators 33, 54, 82 sine 40, 231
REM statement 7, 229 , 267 slash ( / ) 296
reserved words 27, 245-246, 276 soft switches 253, 259
I RESET I key 16 I SOLID-APPLE I key 110, 262
reset vector 16 space bar 19, 21
restarting the system 96, 112, 176, space character 99, 101 , 105, 231
181 S PC function 113, 120-121 , 231 ,
REST OR E statement 106,108, 249
229, 250 speaker 130, 264
Restoring Normal Error Handling S PEE D ~~eme~ 128, 231
71 S QR function 40, 232, 249
RESUME statement 69, 70, 229, square root 40, 232
249, 265 statements 3, 223, 269
return address 63,66, 227 see also names of statements
step value 57ft
stepwise refinement 189
Index 335
STOP statement 17, 73, 216 user-defined function 44-45
STR$ function 89, 232 USR function 172, 233
string(s) 28, 81 , 113, 229 , 232, 233, utility strobe 131 , 261 , 264
270, 275ft, 293,295
comparison 82 V
constants 28, 81 , 83 I.JAL function 83, 86, 90, 102, 105,
conversion 89 107, 233
input 99 validation of data 187
null 28 values, logical 33, 54
pOinters 275- 277 variable(s) 25ft, 51 , 97, 98, 177,
storage 179 216, 268
variables 26, 28,44, 83, 102, argument 44
104,105, 107 index 55, 57, 58, 60
STR I NG TOO lONG error 84, integer 2627, 44, 58
85, 114, 251 name 26, 293
subroutine(s) 10, 61 ft, 171 , 229, real 25, 27, 44, 58, 270, 275ft
250, 269, 270, 276 string 26, 28, 44, 102, 105
call 61 l,' l I N statement 140, 234
execution 220 I.'TA B statement 119, 120, 124,
nested 62 181 , 234, 256
subscripts 29, 77, 79
substrings 86, 295 W
subtraction 32, 36
WA I T statement 174, 234, 249
syntax definitions 235ft
wraparound 4, 120, 122
syntax error 13, 14, 54, 58, 105,
107, 143ft, 166, 251 X
T ;.mRAW statement 151 , 161ff, 230,
231 , 234
TAB function 113, 120, 121ff, 126,
;.( PLOT statement 246
181,232, 249, 254
TAN function 41 , 233 y
tangent 41 , 233
tape cassette 13, 14, 110, 156, 158, Z
165, 228, 230, 231 , 297ft
termination 218, 232 zero page 278
text 142, 253
window 115, 119ft, 129, 136, 143,
221 , 253ft Cast of Characters
TE :n statement 119, 136, 143, " (double quotation marks) 28, 81 ,
233, 258 99, 102, 270
T RACE command 180, 181 , 226, iP (number sign) 96, 111 , 180, 246
233, 294 $ (dollar sign) 26, 29, 82, 88, 251 ,
trigonometric functions 40-41 259
true 33ft 'X, (percent character) 26, 28
truncation 28, 39, 51 , 65,86, 88, &: (ampersand) 246
91 , 117, 120ft, 283 ( ) (parentheses) 37, 250, 276
T Y PE MISMATCH error 87, 88, * (asterisk) 31 , 32
251 + (plus sign) 31 , 36, 84, 105
I (comma) 98ft, 105, 113ft
U - (minus sign) 31 , 36, 105
unconditional branch 50, 220 • (period) 105
UNDEF 10 FUNCTI ON error 251 / (slash) 31 , 296
UNDEF 10 STA T EMENT error 12, (colon) 5, 98ft, 105, 106, 177, 192,
50, 51 , 64, 251 , 268 246, 267, 296, 301
I UP-ARROW I key 18, 19, 241 (semi-colon) 113ft, 122, 267, 269
336 Index
- <: (less than) 34
<: = or = <: (less than or equal to) 34
= (equal sign) 30, 34, 44, 129, 137,
145, 163, 246
:> (greater than) 34
:> = or =:> (greater than or equal to) 34
<: :> or :> <: (not equal to) 34
? (question mark) 97,116, 294
] (right bracket) 4, 16, 119, 247
\ (backslash) 4, 18
. (caret) 31
80-ColumnTextCard 4, 112ft, 119,
124, 125, 127, 222, 254, 287ft
Index 337
Apple II Control Input/Output
r GoTo n Branch to line n IN# n Accept input from slot n
ON expr GOT 0 n 1 , n2 , n3 , . . . IN# 0 Accept input from keyboard
Branch to line n 1, n2, n3, ... INPUT s j x, y, Prompt with string s , then read
Applesoft BASIC depending on value of expr
I F cond THE N s 1 : s2 : s3 : .. .
z values into variables x, y , z ; if s
omitted , ? is used
Execute statements s 1, s2, s3, . GET c Read one character into
r Quick Reference Card FoRv = xToySTEPz
. . if condition cond is true
READ x, y, z
variable c
Read values from D A T A list
Begin loop for all values of v into variables x, y, z
from x to y by z ; if S T E P DATA x, y, z Add values x, y, z to D A T A list
omitted, 1 is understood RESTORE Restart D A T A list from
NDnv Repeat loop for next value of v beginning
GoSUBn Branch to subroutine at line n RECALL a Read array a from tape
RETURN Return from subroutine to point PDL (n) Read dial of hand control n
of call
Editing and Cursor Control Operations on Whole Programs ON expr GoSUB n1 ,n2 ,n3 , . . . PR# n Send output to slot n
Branch to subroutine at line n1 , PR# 0 Send output to display screen
ILEFT - ARR OW I Erase previous character NEW Erase current program , reset all
variables
n2, n3, . . . depending on value PRINT x, y, z Display or print values x, y, z
I RIGH T-A RRowl Recopy character under cursor
I CONTROL I-}( Cancel input line CLEAR Reset all variables ofexpr STORE a Write array a to tape
Display current program POP Remove last return address
LIST
A from subroutine stack without TE)<T Display text
I Es c i Move right ; leave escape mode LI ST n1-n2 Display from line n1 to line n2
B branching HOME Clear screen and send cursor to
I Esc l Move left; leave escape mode RUN Execute program from
oNERR GoTo n Establish error-handling routine top
I Esc l C Move down ; leave escape mode beginning
D beginning at line n Start next item at cursor position
IEs cl Move up ; leave escape mode RUNn Execute program starting at
RESUME Reexecute statement causing Start next item at next tab
linen
I RUN name Load and execute program error pOSition
I Es c l Move up; remain in escape
r mode name from disk STOP Halt execution with message SPC (x) Display or print x spaces
J identifying line (P R I NT statement only)
I Esc l Move left; remain in escape LOAD Load program from tape
Load program name from disk END Halt execution with no message TAB (x) Move cursor to column x
mode LOAD name
IEscl K Move right; remain in escape SA l.' E Save current program on tape (P R I NT statement only)
HTAB x Move cursor to column x
r mode SA l.' E name Save current program on disk
String Operations l.!TAB Y Move cursor to line y
lEse I M Move down ; remain in escape as name
mode PoS (0) Current horizontal cursor
c After I ESCI, arrow keys are the same as I , J , K, M Interrupting and Resuming
+
LEN (s)
LEFT$ (s, x)
Concatenate strings
Length of string s
Leftmost x characters of string s
I Nl.'ERSE
position
Display text in black-on-white
r MID$ (s, x, y characters beginning at
FLASH Display flashing text
IEsc l E Clear to end of line I CO NTROL I -S Suspend output (any key to NORMAL Display text in white-on-black
resume)
y) position x in string s
SPEED= x Set text display rate to x (0
IEsc l F Clear to end of screen
r IEsc l @ Clear entire screen ; move I CONTROL I-C Interrupt program execution
RIGHT$ (s, x) Rightmost x characters of string
s
minimum, 25 5 maximum)
cursor to top CON T Continue execution after
r- STR$ (x) String representing numeric
I CONTROL I-C , STOP, or END
value x
DELn1,n2 Delete from line n 1 to line n2 I CONTROL I- I RESET I Cancel program execution
l.'AL (s) Numeric value of string s
r CHR$ (x) Character with ASCII code x
ASC (s) ASCII code for first character of
Statements and Lines Variables
r string s
Lines typed without a line number are executed Type Name Range
r immediately ; those with a line number are saved for
later (deferred) execution.
Real AB + /- 8,88888888 E + 37
Integer AB'X, + /- 32767
r Separates multiple statements
String AB$ 0 to 255 characters
on same line where A is a letter, B is a letter or digit. Name may be
REM Remarks for human reader more than two characters , but only first two are
significant.
Arrays Precedence of Operators
Graphics Utility Statements
Type Typical Element Parentheses
(innermost first) GR Display low-resolution graphics PEE K ( addr ) Contents of memory location
Real AB (XI y l z) COLOR = Set low-resolution display color addr
AB 'X, ( XI y l z )
+ NOT Signed arithmetic, X
Integer logical " not" tox PO K E addr I x Store value x at memory
String AB$ (XI y l z) PLOT X I Y Plot single block at column x , location addr
Exponentiation
where A is a letter, B is a letter or digit. Name may be * / Multiplication ,
division HLIN x1 I x2
rowy
Draw horizontal line from
CAL L addr Execute machine-language
subroutine starting at location
.-
..,.I
more than two characters , but only first two are AT Y column x1 to column x2 in row y addr
significant. Array size limited only by available
+ Addition,
l.IL I N y1 I y2 Draw vertical line from row y1 to US R (x ) Execute user-supplied
Subtraction
memory. row y2 in column X machine-language function
< > Relational operators AT X
SCRN (x I y) Color on screen at column x, routine with argument x ,
DIM a (x Y I z) Define array a with maximum
<= = < WA I T addr Suspend execution until bit ...J
I
>= => rowy I
subscripts x, y, Z m1 I m2 pattern specified by masks m1,
<> >< Columns numbered from 0 to 38 ; rows from 0 to 38 m2 appears at location addr
AND Logical " and "
OR Logical " or" in mixed text and graphics, 0 to 7 in full-screen a HIM EM: addr Set highest memory address
Arithmetic Operators graphics. available for variable storage to I
addr ~
Assign value to variable (L E T H GR Display high-resolution L 0 MEM: addr Set lowest memory address
optional) Arithmetic Functions
graphics, page 1 ; mixed text available for variable storage to
+ Addition ABS (x) Absolute value of x and graphics addr
Subtraction SGN (x) Sign of x H GR 2 Display high-resolution F RE (0) Amount of available storage
*/ Division
INT (x)
(x)
Integer part of x graphics, page 2; full-screen
graphics
remaining
SQR Square root of x
Exponentiation SIN (x) Sine of x radians H COL 0 R = X Set high-resolution display color T R ACE Display line number of each
COS (x) Cosine of x radians tox statement executed
TAN (x) Tangent of x radians H P LO T X I Y Plot single point at column x , NOT R A CE Stop displaying line number of
Relational Operators ATN (x) Arc tangent, in radians , of x rowy each statement executed
Equal to D(P (x) Exponential of x H P LOT x1 I y1 TO x2 I y2 TO x3 I y3
LOG (x) Natural logarithm of x Draw high-resolution lines from
< Less than
column x1 , row y1 to column x2 ,
:> Greater than
RND (x) If x > 0 , generate random row y2 to column x3 , row y3
<= = > Less than or equal to
number between 0 and 1 H P LOT TO Extend previous line to column
>= =( Greater than or equal to
If x = 0 , repeat previous Y X, rowy
<:> >< Not equal to
random number
X I
Yield value 1 if true , 0 if false. Can also be used to If x < 0 , begin new repeatable Columns numbered from 0 to 2 78 ; rows from 0 to
sequence of random numbers 1 58 in mixed text and graphics, 0 to 1 8 1 in full-
compare strings .
screen graphics.
DEF FN (x) Define function
Logical Operators = expr SHLOAD Load shape table from tape
AND
OR
NOT
Both true
Either or both true
Is false
DRAW n AT
xI Y
){oRAW
XI Y
n AT
Draw shape number nat
column x , row y
Erase shape number nat
column x , row y
-
SCALE = x Set scale factor for drawing
Interpret 0 as false, nonzero as true . Yield value 0 if shapes tox
false, 1 if true . ROT = x Set rotation for drawing shapes
tox