.np
.fs 20
.ce
SOFTWARE DYNAMICS
.sp 2
.ce
6800/6809 BASIC COMPILER V1.4
.sp 19
.ce
10TH PRINTING
.sp
.ce
COPYRIGHT (C) 1977 SOFTWARE DYNAMICS
.sp
.ce
ALL RIGHTS RESERVED
.pa
.np
.fs 14
.ce
NOTICE
.br
.ce
------
.sp 4
This manual describes version 1.4 of the Software Dynamics
BASIC compiler system for 6800/6809 microprocessors.  The
information given in this manual has been carefully checked
and is believed to be entirely reliable.  However, no
responsibility is assumed for inaccuracies.
.sp
Software Dynamics reserves the right to change specifications
without notice.
.sp
.pw 120
.ll 100
.im 11
*********************************************************************
** SD software is sold on a single copy per computer basis, and is **
** covered by U.S. copyright laws.   Unless a written exception is **
** obtained from SD,  the software must be used only on the single **
** computer whose unique,  SD-assigned  serial number matches that **
** for which the software was purchased.   Copies for  any purpose **
** other than archival storage,  or use on other than the assigned **
** serial numbered CPU are strictly prohibited.                    **
** USE  OF THIS  MANUAL OR THE SOFTWARE  IT DESCRIBES  CONSTITUTES **
** AGREEMENT BY THE USER TO THESE TERMS.                           **
*********************************************************************
.ll 65
.pw 85
.sp

SDOS is a registered trademark of Software Dynamics.
.sp
This manual was produced by TYPE, a document-producing program written in SD
BASIC.
.he BASIC 1.4 MANUAL 04/83
.sh SECTION I: INTRODUCTION AND BASIC CONCEPTS
.il Copyright (C) 1977 SD
.pa 1
.bp
.tc
SD BASIC, A COMPILER VERSION OF BASIC.
.sp
.tc
Software Dynamics BASIC was designed to be a powerful
programming tool for building production business applications and 
high-performance process control programs.  To
meet this goal, SD BASIC contains the following features and
many more:
.sp
1) Compiled code: gives higher packing density for the
application program, since only the runtime package and the
compiled program itself reside in memory at execution time.
(Compiled program size is about 20-40% of the source, in
bytes).
.sp
2) More power: since space normally used by other BASICs for
editing, listing, and statement analysis is used for extended
string operations, floating point, file I/O, formatted
output, and more.
.sp
3) Wide variety of structured programming facilities made
possible by the compiler -- nested conditionals,
IF-THEN-ELSE, WHILE/UNTIL DO, etc.
.sp
4) Decimal floating point for business applications.
Accuracy to a minimum of 9 digits; dollar values of up to
$100 million, represented in pennies.
.sp
5) PRINT USING for formatted output.
.sp
6) Faster execution since syntax analysis of a line is not
performed each time the line is executed (performance
improvements of 2 to 10 times over conventional interpreters are normal).
.sp
7) 32 character variable names and line labels, which
simplify program coding and maintenance.
.sp
8) Singly and doubly-dimensioned numeric arrays.
.sp
9) Character strings and string operations (substring,
length, concatenation), including string "arrays" (vectors).
.sp
10) Compile time error diagnostics point to actual error.
.sp
11) Assembly language interface via "CALL" statement.
.sp
12) File I/O to ASCII and binary files.
.sp
13) Data initialization facility.
.sp
14) Parameterized, multi-line subroutines and functions.
.sp
15) Common and chaining allowing multiple module applications.
.sp
16) Full access to operating system I/O facilities.
.pa
.tc
INTRODUCTION
.sp
BASIC is a popular, applications-oriented programming
language.  This document describes how to use the Software
Dynamics version of BASIC, implemented on a broad range of
680x microprocessor computer systems.  The reader should be
generally familiar with BASIC; there are several excellent
primers for those new to the game.
.sp
BASIC, as implemented by Software Dynamics, is a compiler
language, not an interpreter as are most BASICs.  Two main
advantages are derived by this approach:
.sp
        1) Faster execution.
.sp
        2) Programs are smaller (more program in same space)
.sp
Furthermore, the Software Dynamics BASIC has many features
normally found only in BASICs on larger computers, such as
sophisticated string handling and file I/O facilities.
.sp
.tc
NOTATION:
.sp
The following notation is used in this manual:
.sp
$xxxx          A hexadecimal value or memory address, as
               accepted by standard 6800/6809 assemblers.
.sp
<CR>           The ASCII character code $0D, known as
               Carriage-Return and used to mark the end of a
               line of text.
.sp
.im 1
...            Some indefinite sequence of statements or
               expression(s)
.sp
.pw 120
.ll 100
.nj
.im 3
text...        means a "continuation" line (see USING SOFTWARE
& moretext     DYNAMICS BASIC).   This is logically equivalent to:
               text moretext.
.ll 65
.pw 85
.ju
.sp
UPPERCASE      A word that represents the keyword
               "UPPERCASE"; i.e., FOR means the keyword FOR.
               Example variable names are also capitalized.
.sp
lowercase      The name of a definition, i.e., statementlist
               or conditionalexpression.
.sp
linenumber     A line number or a line label name.
.sp
.pa
.tc
PROGRAM ORGANIZATION
.sp
BASIC is a procedure-oriented language: the user expresses
the activity he desires the computer to perform, in a set of
explicit commands to perform computations and make decisions.
.sp
Each of the commands is called a statement.  BASIC has some
40 different kinds of statements and 40 different functions;
the form and function of each is individually discussed,
below.
.sp
A statement list is a set of executable statements separated
by the backslash ("\") character.  An optional <CR> character
is allowed after each backslash separating statements, so a
statement list may span several physical text lines.  Note
that a REM statement, if included in a statement list, is
always the last statement in that statement list.  A single
statement (if not trailed by a "\") is a statement list.
.sp
A "line" is a statement list, followed by a <CR> character
(the traditional BASIC definition of a line is a statement
followed by a <CR>).  Note that with this definition a "line"
can span several physical text lines.
.sp
A "block" is a statement that has an embedded set of lines.
A block is introduced by certain statement formats, and
terminated by a keyword that depends on the introducing
statement.  The set of lines embedded in the statement is
called the block body (an example of a block in traditional
BASIC is FOR-NEXT).  Execution of the block body is
controlled by the introductory statement.  Note that a block
can be part of a line.  Wherever "blockbody" is shown in this
manual, it may be replaced by a statement list (see BLOCK
BODIES).
.sp
A BASIC program consists of a set of lines.  Traditionally,
each line is numbered to indicate the normal sequence in
which the lines are executed.  These line numbers appear at
the left end of the line and may be any value from 1 to
65535.  Good programming practice dictates that line numbers
be separated by some numeric distance, say 10, so that if
programming errors are found, or changes made to the program,
new lines with numbers in between those which already exist
can be created.  With SD BASIC, line labels may also be used,
as well as line numbers.  A line label is any sequence of up
to 32 letters or digits, starting with a letter, (i.e., LABEL
is a valid label).  A label name may not be identical to a
reserved keyword (see VARIABLES).  When a line label is used to "number" a
line, a label must be followed by a ":" character.  A line
label may be on a line by itself, whereas a line number may not.
Heavy use of labels makes programs more readable, and thus
more maintainable.  Throughout the rest of this document, the
term line number or line label are used interchangeably.
Line numbers are only needed if the line is referenced by
another part of the BASIC program.
.pa
Example:
.sp
.nj
.pw 120
.ll 100
.im 21
       10 REM **** PRIME NUMBER CHASER ****
       20 REM PRINTS OUT FIRST 100 PRIME NUMBERS
       30 DIM PRIMES[100],CANDIDATE/3/,NPRIMES/1/
       35 PRINT "Prime Finder"
       40 LET PRIMES[NPRIMES]=2
       LOOKFORANOTHERPRIME:
           FOR PRIMESELECTOR=1 TO NPRIMES
           X=PRIMES(PRIMESELECTOR)
           LET Q=INT(CANDIDATE/X)
           IF Q<X THEN FOUNDNEWPRIME
       110 IF Q*X=CANDIDATE THEN 120
       105 NEXT PRIMESELECTOR
       FOUNDNEWPRIME: LET NPRIMES=NPRIMES+1\PRIMES[NPRIMES]=CANDIDATE
       120 LET CANDIDATE=CANDIDATE+2
           IF NPRIMES <> 100 THEN GOTO LOOKFORANOTHERPRIME
           FOR PRIMESELECTOR = 1 TO 100
           PRINT PRIMES(PRIMESELECTOR)
           NEXT PRIMESELECTOR
           PRINT 'All Done!'
       200 STOP
           END
.ju
.ll 65
.pw 85
.sp
The above program is numbered in a conventional way for BASIC
programs, with the exception of some lines without numbers,
two lines with a label, and one line with a line number out
of order (see below).  Note that when several statements are
"grouped" in the same line (line FOUNDNEWPRIME), they must be
separated by a "\" (backslash) character.  A FOR-NEXT block
appears in the program.  The lines between FOR and NEXT
comprise the body of the FOR-NEXT block.
.sp
When a BASIC program is executed, execution starts with the
first statement in the first line (the statement at the top
of the page of a listing of the program).  The statements
within a line are executed from left to right if there are
more than one.  When a line is completely executed, control
flows to the next line down the page (of the program
listing), and its component statements are executed from left
to right.  Certain statements change the flow
of control explicitly (i.e., GOTO, GOSUB, NEXT,
ON, IF, etc.).  If control flow is redirected, SD BASIC
executes lines sequentially from the new target point until
control flow is changed again.  Note that control flow is NOT
directed in sorted line-number order as in conventional BASIC
programs, but rather in top-to-bottom of page order.  This
is, however, compatible with standard BASIC programs listed
in line-number order.
.pa
.tc
VALUES
.sp
BASIC programs can operate on two kinds of data: real numbers
and character strings.  A specific real number or string is
called a value.
.sp
Number values used by BASIC are decimal (floating point) 9
digit precision numbers (decimal is used to facilitate
business applications).  Numbers used for dollar amounts
between plus or minus 100 million dollars are kept to 10 digit
accuracy (exact to the penny).
.sp
Numeric values are limited to the range of
plus or minus .9999999999 times 10 to the plus or minus 126.
.sp
Strings are groups of 8 bit data items (bytes), which
normally contain ASCII codes for letters, digits,
punctuation, etc.  A string value may be from zero to 65534
(not 65535) characters in length.
.pa
CONSTANTS
.tc
.sp
Constants are the means by which the programmer introduces a
particular value into the program, permanently.  Note that
line numbers are not really constants, since they only serve
to label a line, not to introduce a value into the program.
.sp
Number constants consist of digit strings with an optional
exponent specification, and represent real values in the
program.  At least one digit must be given.  A decimal point
can be placed anywhere in the digit string.  The exponent is
specified by writing "E" (or "e") followed by "+" or "-" or
nothing, followed by one to three digits for the exponent
value itself.
.sp
Examples of numeric constants:
.sp
       5       2.7     0000300         .9999999999E126
       .007    6E-2    .1401e+76       12E12
.sp
BASIC also accepts positive integer hexadecimal constants in
the range 0 to 65535.  The form of a hexadecimal constant is
a colon followed by one to four hexadecimal digits (0-9, A-F
or a-f).  A hexadecimal constant may be used anywhere a
numeric constant may be used.
.sp
Examples of hexadecimal constants:
.sp
       :0      :ABC4   :2F     :4f3
.sp
Two special constants, named TRUE and FALSE, represent the values
1 and 0, respectively.
.sp
String constants consist of a quoted sequence of characters
which do not contain the quote.  The quote character may be
either " or ', but it must be the same at both ends of the
string constant.  The string value represented is the
sequence of ASCII-coded characters which comprise the string
body (everything but the quotes).  Upper and lower case
characters are preserved exactly as written in the body of
the string.  A single quote may appear in a string constant
which is delimited by double quotes, and vice-versa.  An end
of line character <CR> may not appear in a string constant.
The null or empty string is written as '' or "".  A string
constant may not exceed 127 characters in length including
the quotes.
.sp
Examples:
.sp
       "ABC"   'BE"FG'         ".1401E+76"     ''      "can't"
.pa
VARIABLES
.tc
.sp
BASIC allows the programmer to name quantities which can
change.  These named quantities are called variables.  The
name itself is the variable name.
.sp
BASIC supports two kinds of variables: numeric and string.
Numeric variables are used to represent quantities and can
hold any value specified in the section on constant numbers.
String variables are used to deal with varying length groups
of characters (or bytes), and can hold any value as specified
in the section on string constants.  String variables are
limited to 65534 bytes in length.
.sp
Variable names are composed of letters and digits; the first
character of a name must be a letter.  Lower case letters are
treated as being identical to upper case letters in variable
names.
.sp
Examples of legal numeric variable names:
.sp
        X, B7, INTEREST, Rate, A7773X.
.sp
The length of a variable name is limited to 32 characters by
the assembler.  The name of a variable must not be the same
as any keyword (statement, function name, etc.), or a syntax
error will result (i.e., THEN is not a valid variable name).
A list of keywords may be found in the section on KEYWORDS
(note that keywords may also be written using lower case).
.sp
String variable names require that a "$" character be the
last character of the variable name.  The numeric variable
whose name is the same as a string variable name (except for
the "$") is a completely different object from the string
variable.  String variables have two associated lengths: the
current LENgth, which is the number of characters currently
held by the string, and MAXLEN, which is the maximum
(DIMensioned) length of the string.  This difference is
subtle but very important; failure to understand the
difference will cause many mysterious string subscript
errors.
.sp
Examples of legal string variable names:
.sp
       CUSTOMERNAME$, IN27F$, BUF2$, TEXT$
.sp
.pa
SUBSCRIPTING
.tc
.sp
A vector is a variable which represents a list of numeric
values.  If a vector is named V, the first value in the
vector is named (denoted) V[1], the second value is denoted
V[2], etc.  The value inside the [ ]s is called the
subscript.  A subscript value may be specified by an
expression to allow computation of the desired element of the
vector.  SD BASIC allows 0 as a subscript on numeric vectors.
BASIC accepts ( ) interchangeably with square brackets.
.sp
An array is a variable which represents a rectangular matrix
of values.  The upper left hand corner is named A[0,0]; this
element is in the zeroeth row, zeroeth column.  The 2nd
element of the 1st row is A[1,2], etc.  The value in the Nth
row, Mth column is named A[N,M].  N and M may be expressions
which compute the selected row and column.  N or M may be
zero.
.sp
While SD BASIC does not directly support 3 or higher
dimensional arrays, they may be transparently simulated using
the Uniform Reference facility, as outlined in that section.
.sp
Strings can be selected in their entirety, or in portions.
The notation stringname$[exp1,exp2] means select the
substring of the named string starting in the exp1 position
of the string for exp2 characters.  If B$ has the value
"HELLO" at the moment, B$[3,2] is the string value "LL".  The
substring selected must not overlap the end of the current
string value (i.e., exp1<1 or exp1+exp2>current length of the
string), or a subscript error will occur.  If exp2 is zero,
no subscript error can occur.
.sp
The notation stringname$[exp] or stringarrayname$(exp1)[exp]
is called a byte subscript, and means the "exp"th slot of the
string; this form can appear only in numeric expressions and
represents the numeric value of the expth byte of the string
(as opposed to a single character string).  Exp can be from 1
to the DIMensioned size of the string; the current length of
the string has no effect on byte subscripts.  Zero may not be
used as a byte subscript.
.sp
A string array is a variable which represents a vector of
strings (a better name would have been string vectors, but
historical reasons prevent changing it).  Each slot of a
string array holds a variable length string.  The number of
strings in a string array is specified in a DIM statement.
The notation stringarrayname$[exp] selects the "exp"th string
of the array; exp must round to a value greater than or equal
to 1.
.sp
A substring selector or a byte subscript may be appended to
the string selector to select a portion of that string, as
desired.
.pa
A typical string array might contain one sentence in each
slot, with the array representing a limerick.  Then the
string array would have 5 slots; typical filler material
might be:
.sp
.nj
LIMERICK$[1] has "There is a nice compiler BASIC"
.br
LIMERICK$[2] has "with features that make it like magic"
.br
LIMERICK$[3] has "Programs are easy to read"
.br
LIMERICK$[4] has "and run with great speed"
.br
LIMERICK$[5] has "making other BASICs seem tragic."
.ju
.sp
Then LIMERICK$[3](14,4) selects the substring "easy" and
LIMERICK$[3](1) contains the value :50.
.sp
Any variable which can be subscripted must have the maximum
bounds specified in a DIM(ension) or COMMON statement.
.sp
If any subscript value used is not an integer, BASIC will
round it to the closest integer (i.e., it will use
I