💾 Archived View for mirrors.apple2.org.za › archive › ftp.gno.org › doc › FAQs › asoft.txt captured on 2023-05-25 at 00:43:45.
View Raw
More Information
-=-=-=-=-=-=-
From: nathan@visi.com (Nathan Mates)
Newsgroups: comp.sys.apple2,comp.answers,news.answers
Approved: news-answers-request@MIT.EDU
Followup-To: comp.sys.apple2
Subject: Applesoft BASIC Frequently Asked Questions (FAQ)
Archive-name: apple2/applesoft
Posting-Frequency: monthly
Last-modified: February 16 1998
Version: 0.27
URL: http://www.visi.com/~nathan/a2/faq/asoft.html
The Applesoft BASIC FAQ
NOTE: this FAQ is in beta form, and is still being written. Expect a few
minor continuing changes in its layout, content, and correctness. Most info
should be correct-- I'd like to be notified of any problems noted in the FAQ.
This document attempts to give a detailed and correct set of answers
about Applesoft BASIC, an interpreted programming language for the
Apple II series of computers. It is also intended as a reference for
commands and the like; it may at once time in the future include
tutorials, but does not do so now.
DOS 3.3 and ProDOS command line commands are not included in this FAQ;
they have a FAQ of their own at
http://www.visi.com/~nathan/a2/faq/dos.html. I do cover some disk I/O
from within Applesoft programs, however, in this FAQ.
Copyright (c) 1997 by Nathan Mates (email: nathan@visi.com), all
rights reserved. This document can be freely copied so long as 1) it
is not sold, 2) any sections reposted elsewhere from it are credited
back to this FAQ with the FAQ's copyright info and official WWW
location (http://www.visi.com/~nathan/a2/faq/asoft.html) left in
place.
This FAQ may not be sold, bundled on disks or CD-ROMs, reprinted in
magazines, books, periodicals, or the like without prior consent from
the maintainer, Nathan Mates. Exceptions are explicitly granted for
Joe Kohn's Shareware Solutions II newsletter, and Jim Maricondo's
Golden Orchard CD-ROM collection. Email me for permission otherwise.
Further, please do NOT make a copy of this FAQ and post it on the web;
I'm continually updating and fixing sections of it. A html link is
fine.
Disclaimer: I've tried to make this FAQ as accurate as possible, but
there's the chance that it's not perfect. I apologize in advance for
any slipups. Until I am confident that all information is 100%
accurate, you are advised that you are following all info at your own
risk. I will fix any problems found with this FAQ, but will not be
held liable for the results of problems.
Table of Contents
Section 1: General Intro to this FAQ and Applesoft Environment
1.1 Statement of purpose
1.2 Conventions and the like used by this FAQ
1.3 Determining which OS is running
1.4 Immediate mode vs. Deferred execution
1.5 Entering and running programs
Section 2: General language reference
2.1 Numeric Expressions and Assignments
2.2 String Expressions and Assignments
2.3 Flow of control
2.4 Variable names & conventions
2.5 Memory Management/Use
Section 3: Input/Output to Text and Graphics screens
3.1 'PRINT' and text formatting
3.2 Mousetext and special text output
3.3 Text input from the keyboard
3.4 Low Resolution (Lores) Graphics
3.5 High Resolution (Hires) Graphics
3.6 Hires 'Shapes' [Not done yet]
3.7 Double High Resolution (Double Hires) Graphics
Section 4: Miscellaneous tasks
4.1 Sound Generation
4.2 Reading paddles/joysticks
4.3 Program comments
4.4 Internal data storage
4.5 Error Handling
4.6 Random numbers
Section 5: Disk Input/Output
5.1 General Intro and simple commands
5.2 Binary files
5.3 Text File I/O
Section 6: Applesoft command reference by name
ABS, AND, ASC, AT, ATN, CALL, CHR$, CLEAR, COLOR=, CONT, COS,
DATA, DEF, DEL, DIM, DRAW, END, EXP, FLASH, FN, FOR, FRE, GET,
GOSUB, GOTO, GR, HCOLOR=, HGR, HGR2, HIMEM:, HLIN, HOME, HPLOT,
HTAB, IF, IN#, INPUT, INT, INVERSE, LEFT$, LEN, LET, LIST,
LOAD, LOG, LOMEM:, MID$, NEW, NEXT, NORMAL, NOT, NOTRACE, ON,
ONERR, OR, PDL, PEEK, PLOT, POKE, POP, POS, PRINT, PR#, READ,
RECALL, REM, RESTORE, RESUME, RETURN, RIGHT$, RND, ROT=, RUN,
SAVE, SCALE=, SCRN, SGN, SHLOAD, SIN, SPC, SPEED=, SQR, STEP,
STOP, STORE, STR$, TAB, TAN, TEXT, THEN, TO, TRACE, USR, VAL,
VLIN, VTAB, WAIT, XDRAW, &
Section 7: Error codes and messages
7.1 Applesoft Error codes
7.2 DOS 3.3 Error codes
7.3 ProDOS Error codes
Section 8: Miscellaneous Questions
8.1 How do I list to a file or transfer Applesoft to another
platform?
_________________________________________________________________
Sections planned to add to this FAQ:
Error codes in more detail
Fun tricks: Loading at alternate addresses, optimizing for size/speed
Peeks, Pokes, Calls, ROM, memory reference [I don't trust any out
there to be correct, given the number of holes that have been poked in
existing ones]
_________________________________________________________________
Section 1: General Intro to this FAQ and Applesoft Environment
1.1: Statement of Purpose
This document is not (yet?) a tutorial, instructions on how to
program, or the like. It is assumed that the reader has at least a
basic introduction to programming, such as variables, flow of
execution, as well as a general understanding of either DOS 3.3 or
ProDOS for the Apple II.
With the proliferation of Applesoft BASIC addons in the 70s, 80s and
90s, this FAQ does not attempt to cover any of them, though it may
make reference to a few of them from time to time. The only "variants"
to Applesoft that will be commented on in this FAQ are (1) the version
built into the ROM of all Apples since the ][+, (2) the ROM version
running under DOS 3.3 and 100% compatible clones, (3) the ROM version
running in conjunction with ProDOS's BASIC.SYSTEM. Most of the time,
these versions are nearly identical, so Applesoft information should
be regarded as applying to all 3 unless otherwise specified.
A few versions of Applesoft, namely the ones loaded from cassette and
disk on systems without Applesoft in ROM, lack a few features. Those
differences may be noted from time to time, but those notations may
not be complete yet.
About the only change in the ROM versions of Applesoft was the
inclusion of lowercase support starting with the //c and then
spreading to the enhanced //e, GS and IIc+. With that, Applesoft could
be entered in lowercase, but everything except for strings which
remained untouched would be uppercased. Also, the //c, IIc+ and GS
have no cassette port, so the cassette functions were removed. Support
for double lo-res was added instead.
1.2 Conventions and the like used by this FAQ:
Applesoft commands and the like are shown in uppercase and usually
within single quotes ('). For example, 'PRINT "HELLO, WORLD"' is the
way for the computer to announce to the world that it's alive, and
also a simple test of Applesoft. All Applesoft keywords are noted in
uppercase, and should be a hypertext link to the fuller description in
this FAQ. Optional parts of commands are noted in brackets '[]'. Words
in lowercase are usually intended to represent variables, expressions,
line numbers, etc.
1.3 Determining which OS is running, etc.
First, make sure you are at the Applesoft ']' prompt. Type 'CATALOG'
(case sensitive, even if you're running on a //c, enhanced //e, GS or
the like) and hit return. If you got a '?SYNTAX ERROR' and a beep
despite typing it correctly, you're likely not running under any
operating system. If you get a disk listing of files, you're under DOS
3.x or ProDOS. A DOS 3.x (3.2, 3.2.1 and 3.3, though 3.3 is by far the
most common) catalog would tend to look like
DISK VOLUME 254
- A 003 HELLO
- I 003 APPLESOFT
- B 006 LOADER.OBJ0
[Snip...]
while a ProDOS would tend to look like (in 40-column mode, these would
be wrapped to two lines)
BINSCII.TXT TXT 12 20-AUG-96 20-AUG-96 3:14 5645
Alternatively, you can type 'cat' (ProDOS is not case sensitive; also
this command does not exist in DOS 3.3 in any capitalization
sequence). If you get a disk catalog (and only 40 columns wide), this
is ProDOS. A '?SYNTAX ERROR' is a sign of DOS 3.3.
1.4 Immediate mode vs. Deferred execution
Most Applesoft statements can be typed at the ']' prompt, and they
will be executed immediately. You can set variables, do math, draw
graphics, and a fair number of other things directly. However, stuff
like inputting from the user, most text disk input/output and the like
can only be done from within a running program; an '?ILLEGAL DIRECT
ERROR' will be generated by commands not runnable from the prompt. If
you prepend a 'POKE 51,0' to a command, this will trick BASIC into
thinking your program is running and not complain about immediate
mode. DOS commands may be much harder to fool.
Multiple commands can be entered on one line of immediate or deferred
mode by placing a colon (':') between them. For example, 'A=5: B=6'
sets the values of both variables. [Exception: the 'HIMEM: memaddr'
and 'LOMEM: memaddr' statements must have the colon as part of their
actual syntax]
1.5 Entering and running programs
From immediate mode, if a line starts with a line number, it goes into
the current program and is not immediately executed. Valid line
numbers are 0 through 63999; lines are always kept in sorted order. As
there are no such things as named subroutines or the like, choices for
line numbering are somewhat important. It is usually a good idea to
use a spacing of 5 or 10 between line numbers to make inserting code
later on much easier-- renumbering programs can be a headache. The DOS
3.3 System Master disk came with a renumber program on it ('RUN
RENUMBER' to install it and get some information on how to use it),
but unfortunately ProDOS's BASIC.SYSTEM doesn't have that
functionality, though the disk bundled with Apple's "BASIC Programming
with ProDOS" book has a similar program.
If a line does not start with a line number, it is immediately
executed, should it be a command that can be run from the prompt.
[GOTO, GET, INPUT, and a few others won't work from the prompt.] Any
errors detected will be noted. However, errors (even syntactic) are
not caught within lines you enter into the current program-- they're
only caught at runtime.
Due to the size of the input buffer, a single line of the program is
limited to 255 characters. [Applesoft will start beeping when you get
to 248 characters]. There are several strategies for getting around
this. (1) When typing a line, use '?' instead of 'PRINT'-- it'll be
expanded to the full 'PRINT' when parsed. (2) Use no unneeded spaces--
only type them if they're in the middle of a string (" ") or a DATA
statement. They are not needed to separate terms in mathematical
expressions, etc. (3) Split the line into several lines.
When parsing lines without spaces, Applesoft looks for reserved words
first and separates them automatically, unless they're in the middle
of strings. For example, the following (nonsense) line of code
'10IFPRINT"HINPUT TETHEN"GOTOHLIN56=5' will appear as '10 IF PRINT
"HINPUT TETHEN" GOTO HLIN 56 = 5'
The command 'NEW' clears out any Applesoft program in memory and
clears the contents of all variables; it is not easily undoable. 'RUN'
starts the current program after clearing the contents of all
variables, starting at the lowest numbered line, and continues until
'STOP', 'END', flow of execution reaches the end of the code, or an
unhandled error is encoutered. Altenatively, you can use 'RUN linenum'
to clear all variables and start the program at line #linenum. You can
also do 'POKE 51,0: GOTO n' to start a program at line n without
losing the contents of the current variables.
To delete a single line of code, you can type simply the line number
and press return-- that 'replaces' it with an empty line.
There is minimal text mode support for line editing. When you 'LIST' a
program, you can press the 'esc'[ape] key and then use the diamond of
I/J/K/M (capitalization not important on an enhanced //e, //c, IIc+
and GS; may be necessary on an unenhanced //e) or the arrow keys (//e,
//c, GS and IIc+ only) to move around the screen and the spacebar to
move out of the movement mode. [The ][+ also exits escape mode with
the right or left arrows.] Once out of movement mode, the right arrow
can be used to "type" whatever character the cursor is on. This is
very handy for fixing part of a line, inserting or deleting sections.
When 'LIST'ing off a program, you'll notice that the default list has
quite a lot of padding on the right and left margins, which may make
it hard to "retype" a line without running afoul of the 255 character
limit. However, if you type a 'POKE 33,33' before 'LIST 'ing, (or you
can use 'POKE 33,72' if you're in 80-column mode), you'll signify to
Applesoft that you don't want the big margins, which'll help.
[Unenhanced //es must have an even screen width in 80-column mode;
'POKE 33,73' will work fine on an enhanced //e, //c, IIc+ and GS]
The 'TEXT' command will restore the screen to the normal margins.
_________________________________________________________________
Section 2: General language reference
2.1 Numeric Expressions and Assignments:
All variables can be set by '[LET] varb = expression'. The 'LET' is
totally optional, and is usually omitted as being redundant.
For integer and floating point (real) math, normal arithmatic
precedence and operations are followed. Thus, 'A=5+2*3' will set A to
11, not 21, as that expression with (redundant) parentheses is
'A=5+(2*3)'. Exponentiation can be performed with the '^' operator
('A=2^3' sets A to 8), but there is no remainder (modulus) operator
like in other languages.
The '=' operator behaves as an assignment the first time it's
encountered in an assignment, and equality at all other times. Thus,
'A=B=C' sets A to 1 (true) if B is equal to C, 0 otherwise. This is
significantly different from a number of other languages. However, 'IF
A=B THEN x' does not set the value of A to B. The "not equals" test is
'<>' or '><'.
Integers are automatically promoted to reals when needed. To do the
reverse, use 'varb=INT(expr)'. That converts the value to the highest
integer less than or equal to the expression. Integer values have a
fixed range of -32767 to 32767, so trying to convert from outside that
range will result in an error.
Boolean operators are also available-- integers and reals are treated
as true or 1 if not zero, and false or 0 if zero. Thus, 'A%=5.0 AND 2'
is true. The only boolean operations available are 'NOT', 'AND' and
'OR'
Bitwise operations are not directly supported, even on integers.
Operators have the following precedence; things within the same
precedence level are evaluated left to right:
* Highest precedence: () [parentheses]
* ^ [exponentiation]
* - [unary minus]
* * [multiplication], / [division]
* + [addition], - [subtraction]
* = [equal], <> or >< [not equal], < [less than], > [greater than],
<= or =< [less than or equal], >= or => [greater than or equal]
* NOT [logical complement]
* AND [logical AND]
* Lowest precedence: OR [logical OR]
Applesoft is somewhat concerned about variable types-- if you try and
directly assign a string to a number or vice versa, it'll stop and
complain. There are single-character conversions such as
'varb$=CHR$(varb2)' and 'varb=ASC(varb2$)'. Also, for string to number
coverstions, there is 'var$=STR$(expr)' (converts number to string
form) and 'val=VAL(expr$)' (converts first number found in string to
numeric value)
2.2 String expressions and Assignments
Strings have their own sets of operations-- the '+' operator acts to
concatenate strings, so 'A$=B$+C