Commodore Amiga BASIC (1985)
Commodore Amiga BASIC (1985)
Commodore Amiga BASIC (1985)
I
-L -
1_ -
1_ _
'- -
I
L-
AMIGA
_ Amiga Basic
Amiga Basic was developed by Microsoft Corporation.
Microsoft® BASIC for the Amiga
COPYRIGHT
This manual Copyright \I) Commodore-Amlga, Inc. and Microsoft Corporation, 1985, All Rights Reserved. This
document may not, in whole or in part, be copied, photocopied, reproduced, translated, or reduced to any electronic
medium or machine readable form without prior consent, in writing, from CommodOre-Amiga, Inc.
This software Copyright <I) Microsoft Corporation, 1985, All Rights Reserved. The distribution and sale of this
product are intended for the use of the original purchaser only. Lawful users of this program are hereby licensed only
to read the program, from its medium Into memory of a computer, solely for the purpose of executing the program.
Duplicating, copying, selling, or otherwise distributing this product Is a violation of the law.
DISCLAIMER
THE PROGRAM IS PROVIDED" AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE RESULTS AND PERFORMANCE OF THE PROGRAM IS
ASSUMED BY YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU (AND NOT THE DEVELOPER OR
COMMODORE-AMIGA, INC. OR ITS DEALERS) ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION. FURTHER, COMMODORE-AMIGA DOES NOT WARRANT, GUARANTEE, OR MAKE
ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF, THE PROGRAM IN
TERMS OF CORRECTNESS, ACCURACY, RELIABILITY, CURRENTNESS, OR OTHERWISE; AND YOU RELY ON
THE PROGRAM AND THE RESULTS SOLELY AT YOUR OWN RISK. IN NO EVENT WILL COMMODORE-AMIGA,
INC. BE LIABLE FOR DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY
DEFECT IN THE PROGRAM EVEN IF IT HAS BEEN ADVISED OF THE POSSIBLITY OF SUCH DAMAGES. SOME
LAWS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES OR L1ABLITIES FOR
INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE LIMITATION OR EXCLUSION MAY NOT APPLY.
PRINTED In U.S.A.
CBM Product Number 327273-02 Rev C
Contents
Appendices A-1
Index 1-1
Chapter 1
Amiga Basic
Whatever your reason for using BASIC, you will find that Amiga Basic gives
you all the well-known advantages of BASIC, plus the ease of use and fun
you expect from Amiga tools. Amiga Basic puts the full BASIC language on
your Amiga computer, including BASIC statements used to write graphics,
animation, and sound programs. Also, it has all the familiar features of the
Amiga screen. Amiga Basic has a Menu Bar, a Pointer, and windows and
screens, just like other Amiga tools have.
If you are just starting to learn BASIC, either in a class or on your own,
Amiga Basic will fit right in with your course of study. Amiga Basic is based
on Microsoft BASIC,the most popular programming language in the world,
which works on every major microcomputer.
If you are an old hand at BASIC programming, you'll want to try some of
the special features of this version of BASIC, such as SOUND and WA VB
for making music and sounds, and GET and PUT for saving and retrieving
graphics by the screenful.
Chapters 1 through 7 describe how to use Amiga Basic with the Amiga.
They include general instructions on using the interpreter, editing and
debugging your programs, working with files and devices, and using some of
Amiga Basic's advanced features. Chapter 7 is a guide to using the Object
Editor, a program written in Amiga Basic, which lets you create images to
use in animations with your application programs.
Like all languages, Amiga Basic is always growing, changing, and improving.
Amiga continues to keep its BASIC interpreter up to date with new features.
Here are some of the latest features you'll find in this version of BASIC. All
of the features are described fully in the reference section of the manual.
Amiga Basic provides the tools you need to write programs that work like
and look like they were written for the Amiga. These tools are especially
important if you are a software developer who plans to sell application
programs for the Amiga.
Mouse Support
With the MOUSE function, your BASIC program can accept and respond to
mouse input. The MOUSE function returns the coordinates of the mouse
pointer under various conditions (left button up, left button down,
single-click, double-click, and drag).
Block Statements
Subprograms
Amiga Basic allows subprograms that have their own local variables. Using
subprograms. you can build a library of BASIC routines that can be used
with different programs. You can do this without concern about duplicating
variable names in the main program.
SHARED Statement
Integer Support
The Amiga version includes both 32 and 64 bit floating point support.
Alphanumeric Labels
Both sequential and random access files can be created. Sequential files are
easy to create, while random access files are flexible and quick in locating
data.
• The ability to save and redisplay screen images through the GET
and PUT statements
All of these functions are described in detail under the related commands in
Chapter 8; the Object Editor is described in Chapter 7. Some of the
functions are summarized below.
Amiga Basic programs can produce high quality sound for games, music
applications, or user alerts. The SOUND statement emits a tone of specified
frequency, duration, and volume. As an option, the tone can also have one
of four user-defined .. voices." The WAVE statement lets you assign your
own complex waveforms to each of the voices. SOUND and WAVE can
provide your programs with a rich variety of musical sounds, from the
complexity of a string quartet to the simplicity of a whistled tune.
LINE and CIRCLE are versatile commands for drawing precise graphics.
The LINE statement draws a line between two points. The points can be
expressed as relative or absolute locations. By adding the B option to the
The GET statement saves groups of points from the screen in an array, so
you can store a "picture" of a graphic image in memory. The PUT
statement calls the array back and puts it on the screen. The SCROLL
statement lets you define an area of the screen 'and how much and which
way you would like it to move.
Amiga Basic offers the Object Editor, a program written in BASIC, that
helps you create images of objects to use for animations with your Amiga
Basic applications programs. See Chapter 7 for details on the Object Editor.
This manual provides complete instructions for using the Amiga Basic
Interpreter. However, little training material for BASIC programming is
included. If you are new to BASIC or need help in learning to program, we
suggest you read one of the following:
Dwyer, Thomas A., and Critchfield, Margot. BASIC and the Personal
Computer. Reading, Mass.: Addison-Wesley Publishing Co., 1978.
Getting Started
• Turn on the Amiga power switch. If the Amiga prompts you for
a kickstart diskette, then insert it in the internal drive.
• Put the Amiga Extras disk into any 3 112" Amiga disk drive.
• Open the Extras disk icon. Then open the Amiga Basic icon.
Note: This tutorial assumes that the Amiga Basic screen is using the original
Workbench colors (blue for background, white for foreground, orange, and
black).
At this point, the cursor (an orange vertical bar) appears in the List window,
and you can either type in a new program or retrieve an existing program
and modify it, as you'll see in the next section. Notice that the Title Bar in
the List window is displayed distinctively to indicate that it is selected. while
the Title Bar in the Amiga Basic window is ghosted or displayed less
distinctively to indicate that it is not selected.
The Output window in Amiga Basic not only lets you see the results of a
program. it also allows you to type in commands directly. Any time you
would prefer to type in commands directly in the Output window, click in
the Output window (entitled BASIC). This process is called selecting the
Output window. Notice that Amiga Basic responds with the Ok prompt.
To display the menu titles in the Menu bar. click in the Output window then
press and hold down the mouse Menu button.
--!:)ehectEld Window
• Type
files
To see the files in one of the directories, type the word files followed by the
desired directory name enclosed in quotes. If the disk is in the external
drive, type the word files followed by the drive number in quotes. For
example, if the Extras disk is in drive 1, the following command lists all files
in the subdirectory Bas/eDemos:
files "dfl:basicdemos"
Loading Picture
• Press the mouse Menu button and point at the Project menu
title in the Menu Bar. The menu items that appear are New.
Open, Save, Save As, and Quit.
• Type
basicdemos/picture
A listing of the Picture program appears in the List window. The name of
the Output window changes from BASIC to BasicDemos/Picture.
You may have expected to see a line number at the beginning of each line.
In Amiga Basic. line numbers are optional. To refer to a particular line, give
that line a label or a line number. For example, the Picture program has no
line numbers. However, it has two labels: CheckMouse and MovePicture.
LIST CheckMouse
Notice that the List window scrolls to the CheckMouse label. However, if
you wish to edit in the List window, you must first select it.
Note that when you type a program line. the reserved word doesn't appear
in uppercase until you move from line to line.
• To open the Output window over the List window, choose Show
Output from the Windows menu.
When the program runs, a picture appears in the Output window. You can
move this Picture around by clicking the mouse Selection button anywhere
in the Output window. Try it.
• Choose Show List from the Windows menu. The List window
comes forward again. To edit the program again in the List
window, you must select the List window.
To scroll through the List window line by line, click in it and use the up and
down arrow keys located at the lower right corner of the Amiga keyboard to
move up and down.
To move right or left one character at a time within a program line, use the
right or left arrow keys.
Note: Throughout this manual, whenever you see two keys joined together
with a hyphen. such as SHIFT-Up Arrow, this means that you press and
hold down the first key at the same time that you press the second key. So
SHIFT-Up Arrow means to press and hold down the SHIFT key while you
press the Up Arrow key.
To move to the first line in the program, press ALT-Up Arrow. To move to
the last line in the program, press ALT-Down Arrow.
To move to the right margin of a program line, press ALT -Right Arrow. To
move to the left margin of a program line, press ALT-Left Arrow.
If you want to know more about Picture, see Appendix G, "A Sample
Program," for a line-by-line explanation.
To enter new text, select the insertion point (the thin orange cursor) by
moving the Pointer to the location where you want text and clicking. Then
type in the desired characters.
To select a word, position the pointer over the word and double-click the
mouse Selection button.
• Press and hold down the mouse Selection button in the Title Bar
and drag the entire List window to the left.
• Release the Selection button and move the pointer to the Sizing
Gadget on the lower right side. Press and hold down the
Selection button over the Sizing Gadget, dragging it to make the
List window wide enough to read the program lines.
• Release the Selection button when you are satisfied with the List
Window width.
• Scroll through the Picture listing until you find this line:
CIRCLE(60,60),55,O",ASPECT
Now you are ready to type a new line. Note that Amiga Basic automatically
aligns the cursor with the statement directly above it, saving you the bother
of inserting blank spaces.
CIRCLE(200,60),55,3, "ASPECT
This statement draws an ellipse with the center located at 200,60. It has a
radius of 55 and an aspect ratio equal to ASPECT. If you're using the
original Workbench colors, the number 0 represents blue, and the number 3
represents orange. Every time the WHILE loop is executed, the statement
draws another ellipse with a different aspect ratio (ASPECT). These ellipses
form the sphere.
You might make errors (also known as "bugs") when you type or edit a
program. When Amiga Basic finds an error, it stops program execution and
displays a requester describing the error. Amiga Basic makes sure the List
window is visible and then scrolls the window so the line containing the error
is visible. The statement that caused the error is enclosed in an orange
rectangle. Then you can edit the incorrect line in the List window and run
the program again. This process is called "debugging."
Since you changed the program. only the first sphere moves when you click
the Selection button. Let's change the program so that the both spheres
move together.
• Choose Show List. Observe that Show List doesn't change the
position of the List window.
GET(O,O) (327,127),P
This new GET statement increases the area that moves when you click the
Selection button.
Now, let's change the DIM statement to create an array of 6000 rather than
2500 elements.
• Select the part of the statement that reads 2500 and select Cut
from the Edit menu. (A shortcut is to press the BACKSPACE
key.)
DIM P(6000)
_.Atl'lAn/1Art Statements
Now both spheres move together when you click and drag the mouse.
• Point to the end of the statement and click. putting the insertion
point directly after BF.
Now the color inside of the box will be blue, not white.
CIRCLE(60,60),55,O, "ASPECT
• Type
end
• Choose Step from the Run menu. Step executes the first line of
the program and then the program stops.
• Choose Show List from the Windows menu to open and select
the List window on the right side of the screen.
The next line executes, and the program stops again. Each statement is
outlined in the List window as it executes. There's no output yet, so not
much is happening.
Continue choosing Step and watch the program execute one program
statement at a time. When the section that draws the ellipses is outlined,
observe how it draws the spheres. Each time the WHILE loop executes, it
adds an ellipse with a different ASPECT (aspect ratio) to each sphere.
print aspect
Even though we're not actually debugging Picture, this illustrates a typical
debugging technique that uses what is known as immediate mode. While
using immediate mode, you can enter and execute a command in the Output
window "on the spot." Amiga Basic executes immediate mode commands
right away, displaying the result if there is one. For more information on
immediate mode, see "Operating Modes" in Chapter 3.
• Choose the Save As item from the Project menu. The following
requestor appears:
You can change the name if you want to, or simply click the OK Gadget.
If you didn't change the program's name, you now have two versions of
Picture on the disk: the original, unchanged, Picture2 and the newly edited
Picture. You could have also decided to rename the program as
"myprogram" or any other legal name. That would have preserved Picture
in the form that you found it before your changes.
LOAD "filename"
To edit the loaded program or enter a new program, enter the command:
LIST [<label>]
LIST calls Amiga Basic's full screen editor and lists the current program
starting at the first line of the most recently edited portion. If you specify an
existing label, that line will appear on the top line of the display along with
the lines that follow it.
RUN
To debug the program, you can use immediate mode statements. For
example, you can see the contents of array A with the following statements:
CONT
To quit the Amiga Basic and return to the Workbench, enter the command:
SYSTEM
You can select either yes or no. or select cancel to remain in Amiga Basic.
SAVE ["filename"]
If you omit the file name, a requester appears that allows you to either save
the program under its current name or change the name before saving.
The following section explains how to start and exit Amiga Basic and how to
load and save Amiga Basic programs.
2. Type
AmigaBasic
on the CLI screen (selected from the System drawer) and press
the RETURN key.
There are two ways to exit Amiga Basic and return to the Workbench.
1. Select the Quit item from the Menu Bar's Project menu.
2. Type
system
in the selected Output window and press the RETURN key. Or,
enter SYSTEM as an instruction in an Amiga Basic program.
To run an existing program, you must first load the program into memory.
There are several ways to load a program:
2. If Arniga Basic has already been loaded, you can select the
Open item from the Project menu. This displays a requester
asking you which program you wish to load. Click in the Title
gadget, type in the name of the program, and click in the OK
Gadget (or press the RETURN key).
3. If Arniga Basic has already been loaded, you can type the
LOAD or RUN statements in the Output window. See Chapter
8 for the proper syntax.
Saving a Program
To save a new program, you can either select the Save As item from the
Project Menu or type the SAVE statement in the Output window. See
SAVE in Chapter 8 for the proper syntax of this statement. To file away a
previously saved and now re-edited program, you can either enter the
SAVE command or select the Save item from the Project menu (see below).
Amiga Basic normally saves all new programs in compressed form. To save
programs in protected form, or in ASCII format for a word processor or a
MERGE command, you must give explicit instructions with the SAVE
command in the Output Window. You must also use the SAVE command
(with no option) to change an ASCII file back to compressed format.
When you open Amiga Basic, the Output window appears with the name·
BASIC. It is ready to accept commands. At this point, you can use Amiga
Basic in one of three modes: immediate mode, edit mode, or program
execution mode. The List window is selected when Amiga Basic begins
operating.
Immediate Mode
In immediate mode, Amiga Basic commands are not stored in memory, but
instead are executed as they are entered in the Output window. Results of
arithmetic and logical operations are displayed immediately (when you
request that they be printed) and stored for later use, but the instructions
themselves are lost after execution. Immediate mode is useful for debugging
and for using Amiga Basic as a calculator fqr quick computations that do not
require a complete program.
To begin entering immediate commands, you must first select the Output
window by clicking anywhere in it with the Selection button.
Edit Mode
You are in edit mode when you are working in the List window. The
commands you enter are not executed until you enter a RUN command or
select Start from the Run menu.
There are three separate regions of the Amiga Basic screen: the Output
window, the List window, and the Menu Bar.
• To bring the back window to the front, you click the Front
Gadget.
• To put the front window to the back, you click the Back
Gadget.
• To close the window, you click the Close Gadget located in the
upper left corner.
• To move the window, you press and hold down the Selection
button and drag the Title Bar. (You can also move the Output
window if you resize it.)
You can use the Output window both to enter statements as immediate mode
commands and to display the output from your programs.
• Choose Show Output from the Windows menu (if the Output
window is not visible), and then click inside it.
You can use the List window to enter, view, edit, and trace the execution of
programs. The List window is automatically selected when you first open
Amiga Basic.
• Choose Show List from the Windows menu (if the List window
is not visible). and then click inside it.
The List window becomes visible when the program halts due to an error.
Note: If a program has been saved in a protected file (with the SAVE
command in the Output window). you cannot open a List window for the
file. Protected files can neither be listed nor edited.
There are four menus on the Menu Bar: Project. Edit. Run. and Windows.
You cannot always use all of these menus. A menu title may be displayed
less distinctively as a ghost menu item to indicate that the menu is not
relevant to what you are doing at the moment. Similarly. a ghost menu item
may appear when that item cannot be selected.
Some of the menu items show an Amiga key sequence next to them. such as
Amiga-X for Cut. This means you can press the given key combination
(that is. press the "X" key while holding down the right Amiga key) instead
of choosing the item with the mouse, if you want to. All the menu keyboard
shortcuts use the right Amiga key.
The Project menu contains five items that affect program files. There are no
keyboard shortcuts for the items in the Project Menu.
New gets Amiga Basic ready to accept a new program. It clears the current
program listing from your screen and clears the program from memory. so
you can begin a new program. It behaves the same way as the NEW
statement.
Open tells Amiga Basic that you want to bring in a program that is already
on the disk. To display the names of the programs on the disk. select the
Output window and enter the FILES command. When you choose Open. a
requester appears to ask which program you wish to open. Type in the
name of the desired program, then click the OK Gadget.
Save saves the program under its current name. This means it puts a
program on the disk after you have entered it or made changes to it. Save
saves all new programs in compressed format and saves all revised programs
in whatever format they were loaded in.
To save your program in text or protected format, you must use the SAVE
statement in immediate mode in the Output window. See" Program File
Commands" in Chapter 5 for an explanation of file formats. See SAVE in
Chapter 8 for the syntax of the SAVE statement.
Quit tells Amiga Basic to return to the Workbench. It behaves exactly like
the SYSTEM statement.
The Edit menu has three items that are used when entering and editing
programs. Except for immediate mode commands in the Output window.
you enter and edit all program statements in the List window. Each of the
Edit menu commands has a keyboard shortcut.
Cut deletes the current selection from the List window and puts it in the
Clipboard. Pressing Amiga-X is the same as choosing Cut.
Copy puts a copy of the current selection into the Clipboard without deleting
it. Pressing Amiga-C is the same as choosing Copy.
Paste replaces the current selection with the contents of the Clipboard. If
no characters are selected, Paste inserts the contents of the Clipboard to the
right of the insertion point. Pressing Amiga-P is the same as choosing Paste.
The Run menu has six commands that control program execution. Keyboard
shortcuts are available for four of these commands.
Stop stops the program that is running. Stop behaves exactly like the STOP
statement. Amiga-period or CTRL-C are the keyboard shortcuts for
stopping the current program.
Suspend suspends the program that is running until any key other than
Amiga-S is pressed. Pressing Amiga-S or CTRL-S are the same as selecting
Suspend. Suspend is enabled whenever a program is running.
Trace On/Off is a toggle that turns program tracing on and off for
debugging. If the List window is visible, tracing highlights each statement as
it is executed. Turning Trace on works the same as the TRON statement,
where the last statement executed has a trace rectangle drawn around it. If
no statement has been executed, no rectangle is drawn. This lets you
determine where the program is being stopped. Trace Off works the same as
the TROFF statement where tracing no longer highlights each statement as it
executes.
Step executes the program one step at a time. It stops after each statement.
Pressing Amiga-T is the same as choosing Step. When the List window is
made visible, a rectangular box outlines the statement that was just
executed.
The Windows menu has two items that open windows on the Amiga Basic
screen.
Show List opens the List window on the current program. If a List window
is already opened but covered with the Output window, Show List brings the
List window forward. Pressing Amiga-L is the same as choosing Show List.
To edit a loaded program or to enter a new program, you can also use the
LIST immediate mode command in the Output window.
Show Output opens the Output window. The List window is put behind the
Output window. In order to enter immediate mode commands in the Output
window, you must first click in it.
Editing Programs
The List window appears when you start Amiga Basic. Enter
text and use the regular Amiga Edit menu items--Cut,
Copy, and Paste--to edit the program lines in the List
window.
Editing program lines in the List window is similar to working with regular
text on a word processor.
Here are some reminders about typing and editing text in the List window.
• End each program line with a carriage return. You can have
extra carriage returns in your Amiga Basic programs. However,
these only create blank lines that are ignored when the program
executes.
• You can indent lines of text by using the TAB key. Indenting
makes your program easier to read. The TAB key advances two
characters to the right. When you press the RETURN key at
the end of a line, the cursor descends one line and goes to the
column where the previous line started. This means if the
previous line started with a tab, the new line starts at the same
tab stop. This indentation does not cost additional memory.
• You can precede program lines with line numbers; however. line
numbers are not required.
Selecting Text
• The quickest way to select a single line is to point at the far left
edge of the line and drag the highlighting down one line.
• If you drag the highlighting to the edge of the List window and
keep holding down the Selection button. the window
automatically scrolls. selecting as it goes.
Here are some pointers on scrolling through text in the List window.
• Use the four arrow keys to move the insertion point one
character to the right or left or one line up or down.
• If you press the right arrow key and the insertion point is
already at the rightmost column of the display, the display
scrolls 75 percent to the right. If the display has already
scrolled as far to the right as possible, Amiga Basic beeps to
indicate it can go no further. The left, up, and down arrows
behave in a similar way.
• If you hold the SHIFT key down while you hold down any
arrow key, the display scrolls in that direction. If it has already
scrolled as far as possible in that direction, Amiga Basic beeps.
To open the List window at a specified line, enter the LIST command in the
Output window and include a label or a line number. The List window
opens with that line as the first line.
For example, LIST MovePicture lists the Picture program, beginning with
the MovePicture routine. in the List window.
Debugging Programs
This section describes the four debugging features that Amiga Basic
provides: error messages, the TRON command. the Step option, and the
Suspend option. You can use these features to save time and effort while
removing program errors.
Error Messages
TRON Command
It is easy to remember the TRON command as TRace ON. You are in Trace
mode whenever you choose the Trace On item from the Run menu, execute
the TRON statement in a program line, or enter TRON in the Output
window.
To disable TRON. select the Trace Off item from the Run menu, execute
TROFF in a program line, or enter TROFF in the Output window.
If you have isolated the error to a small part of the program, it is easier and
quicker to turn on TRON from within the program, just before the error is
reached.
Step Option
The Step option executes the next statement of the program in memory. If
the program has been executed and stopped. Step executes the first
statement following the STOP statement. The program then returns to
immediate mode. If there is more than one statement on a line, Step
executes each statement individually. You can choose the Step item in the
Run menu or press Right Amiga-T.
If the List window is visible, Step frames the last statement that has been
executed.
You can advance through a program, step by step, testing results at the end
of each line, and interactively testing variable values by using the PRINT
command in the Output window.
Suspend Option
To create a pause in program execution, you can choose Suspend from the
Run menu or press Right Amiga-S. The pause continues until you press any
key (with the Output window selected) except Right Amiga-S, or until you
select Continue from the Run menu. Suspend is enabled whenever a
program is running.
Don't forget that the contents of the Clipboard are replaced with each Cut
and Copy command. However, a Paste command does not change the
contents of the Clipboard, so you can paste the same contents into different
places in a program as many times as you want.
Sometimes you may want to cut something out of the program without
having it overwrite information you have on the Clipboard. You can do this
by highlighting the text you want to eliminate and pressing the BACKSPACE
key. This is also a good technique when you want to avoid generating "Out
of heap space" error messages, which can occur if you delete a very large
block of text.
Once a program has been suspended, you can use the Output window to
glean useful debugging information in immediate mode. For example, if
your program is causing an error message, and the error occurs somewhere
within a loop, you can find out how many times the program has executed
the loop and all the variable values. You find this out by entering immediate
mode instructions in the Output window to PRINT the variables (for exact
syntax, see "PRINT" in Chapter 8.
OPEN "COIol1:300,N,7,2" AS #1
Printer Option
The Amiga supports a variety of printers. which are listed in the Preferences
tool. If you want your Amiga Basic output to use features such as margin
setting. italics. and so forth, you must specify special printer codes to do so.
For this reason, the Amiga includes a printer driver program for each
supported printer. Each such program converts standard printer codes into
special character sequences that the corresponding printer can understand.
PRT:
SER:
PAR:
The PAR: and SER: devices send output to the parallel and serial ports,
respectively. However, they do not convert your printer codes, and their
use is strongly discouraged for normal purposes. For serial applications such
The PRT: device is used identically to the LPT1: device described above.
LPT1: is a Microsoft device name preserved for portability among different
machines.
When you wish to specially format your program's output, you can include
the appropriate printer codes in the program's PRINT# statements. These
"escape sequences," as they are called, consist of the ESC character (ASCII
27) followed by one or more other characters.
There are a few filename constraints in Amiga Basic. All files have a
filename preceded by an optional volume (or disk) name and/or one or
more nested subdirectory names. The entire identification is called a
"pathname."
Filenames
Amiga Basic pathnames can be from 1 to 255 characters in length, and can
consist of either uppercase or lowercase alphanumeric characters or a
combination of both. Each file or subdirectory name within a path is limited
to 30 characters. No control characters can be used in filenames. Here are
some examples of valid filenames:
Demos: Picture
DF1:AccountsREC
BasicDemos/Picture
Mymemos:Notes/scratchfile
DF1:Worknotes/AccountsREC
As the last two examples illustrate, you can enter a volume or disk name in
front of the subdirectory name. See the AmigaDOS Reference Manual for
further information.
Your Amiga comes with one built-in disk drive. You can connect an
additional disk drive to increase your storage capacity. Even on one-drive
systems, some people will have more than one volume. In this case, you
must explain which volume is to be activated for loading or saving files. To
do this, add the relevant volume name to the filename, separating them by a
colon. In this manner, the volume name can be used in place of a drive
number in a pathname.
If the program file you wish to load is on another disk, press the eject button
next to the built-in disk drive, and insert the disk with the desired file. After
the disk is inserted, use the FILES command to display the files on the disk.
F or example:
FILES "mydisk:"
You can then load the file in the normal way. If the pathname you specify
includes a volume name for a disk that is not currently in the drive, a
requester appears that asks you to insert that volume.
For loading program files, it's best to select the Open item on the Project
menu. To save program files on another disk, it is best to select the Save As
item on the Project menu.
You can also load a program from another volume with the LOAD,
MERGE, or RUN commands. Enter the volume name and filename,
separated by a colon, in the Output window. However, if that volume has
not been previously mounted on the system, an "Unknown volume" error
message is generated. To avoid this, you will first have to eject the disk in
your built-in drive by pressing the eject button. Then you can insert the
volume containing the program you wish to load.
Handling Files
This section examines file 110 procedures for the beginning Amiga Basic
user. If you are new to Amiga Basic, or if you are encountering file-related
errors, read through these procedures and program examples to make sure
you are using the file statements correctly.
The following is a brief overview of the commands and statements you use to
manipulate program files. More detailed information and rules of syntax are
given in Chapter 8. "Amiga Basic Reference." under the various statement
names.
There are three main ways to open a program file. The most common is to
use the LOAD command. When you load a program file. all open data files
are closed. the contents of memory are cleared. and the loaded program is
put into memory.
The two main ways to store your programs are: (1) to select Save or Save
As on the Project menu. or (2) to type the SAVE command in the Amiga
Basic Output window. For information on the Save and Save As selections,
see "The Menu Bar" in Chapter 3. For full details on the SAVE command,
If you wish to protect a program from being listed or changed, use the
"Protected" (,P) option with the SAVE command. You will almost certainly
want to save an unprotected copy of a program for listing and editing
purposes.
If you wish to save the program in ASCII format, use the ASCII (,A) option.
ASCII files use up more room than binary ones, but word processing
programs can read ASCII files, and CHAIN MERGE and MERGE can
successfully work only with programs in this format.
Two types of data files can be created and accessed by an Amiga Basic
program: sequential files and random access files. Each type is described
below.
Sequential Files
Sequential files are easier to create than random access files, but they don't
provide as much speed and flexibility in locating data. The data written to a
sequential file is a series of ASCII characters that are stored, one item after
another (sequentially), in the order written. The data is read back
sequentially, one item after another.
Amiga Basic gives you the option of specifying the file buffer size for
sequential file 1/0. The default length is 128 bytes. This size can be
specified in the OPEN statement for the sequential file. The size you specify
is independent of the length of any records you are reading from or writing
to the file; it only affects the buffer size. A larger buffer size speeds I/O
operations, but takes memory away from Amiga Basic. A smaller buffer
size conserves memory, but produces lower I/O speed.
The following statements and functions are used with sequential data files:
CLOSE LOF
EOF OPEN
INPUT# PRINT#
INPUT$ PRINT
USING# LINE INPUT#
WIDTH WRITE#
LOC
1. Open the file in output (that is. output to the file) mode.
3. After you have put all the data in the file. close the file.
A program can write formatted data to the file with the PRINT # USING
statement. For example. you can use the statement
PRINT#l, U8INC"####.##,";A,B,C,D
to write numeric data to the file with commas separating the variables. The
comma at the end of the format string in PRINT # USING statements
separates the items in the file with commas. It is good programming practice
to use "delimiters" of some kind to separate different items in a file.
WRITE Nl,A,B
to write the values of variables A and B to the file, with commas delimiting
them.
Now let's look at Program 2. It gains access to the file DATAFIL that was
created in Program 1 and displays the names of employees hired in 1981.
OPEN "I",Nl,"DATAFIL"
WHILE NOT EOF(l)
INPUT Nl,N$,DEPT$,HIREDATE$
IF RIGHT$(HIREDATE$,2)"'''81''THEN PRINT N$
WEND
Program 2 reads each item in the file sequentially and prints the names of
employees hired in 1981. The WHILE ... WEND control structure uses the
EOF function to test for the end-of-file condition and avoids the error of
trying to read past the end of the file.
If you have a sequential file on the disk and want to add more data to the
end, you cannot simply open the file in output mode and start writing data.
As soon as you open a sequential file in output mode. you destroy its current
contents. Instead. use append mode (option A). If the file doesn't already
exist. append mode works exactly as it would if you used output mode.
OPEN "A",#l,"FOLKS"
REM***Add new entries
NEWENTRY:
INPUT "NAME" ;N$
IF N$ '" ""THEN GOTO FINISH 'Carriage Return exits loop
LINE INPUT "ADDRESS? ",ADDR$
LINE INPUT "BIRTHDAY? ",BIRTHDATE$
PRINT #1. N$
PRINT #1. ADDU
PRINT #1, BIRTHDATE$
GOTO NEWENTRY
FINISH:
CLOSE #1
END
The LINE INPUT statement is used for getting ADDR$ because it allows
you to enter delimiter characters (commas and quotes).
Creating and accessing random access files requires more program steps
than creating and accessing sequential files. However, there are advantages
to using random access files. One advantage is that random access files
require less room on the disk, since Amiga Basic stores them in a packed
binary format. (A sequential file is stored as a series of ASCII characters.)
The biggest advantage to using random access files is that data can be
accessed randomly; that is, anywhere in the file. It is not necessary to read
through all the information from the beginning of the file. as with sequential
files. This is possible because the information is stored and accessed in
distinct units called records. Each record is numbered.
1. OPEN the file for random access (using mode R). If you use
the alternate syntax of the OPEN statement:
.3. To move the data into the random access buffer, use LSET or
RSET. You must convert numeric values into strings when
placing them in the buffer. To make these values into strings,
use the "make" functions: MKI$ to make an integer value into
a string, or MKS$ to make a single precision value into a string.
LSET N$ = X$
RSET AMOUNT$=MKS$(AMT)
LSET P$ = TEL$
Notice that the dollar value AMT uses RSET, since money is typically right
justified in a data field.
4. To write the data from the buffer to the disk, use the PUT
statement and specify the record number with an expression, for
example:
Program 4 takes information that is input from the keyboard and writes it to
a random access file. Each time the PUT statement is executed, a record is
written to the file. The two-digit record numbers that are input in line 30
should be entered in numeric order.
Program 5 gains access to the random access file DATAFIL that was created
in program 4. When you enter a two-digit code at the keyboard, Amiga
Basic reads and displays the information associated with that code from the
file.
The program can now access the data in the buffer. Numeric values that
were converted to strings by the MKI$ and MKS$ functions must be
converted back to numbers using the "convert" functions: CVI for integers
and CVS for single precision values. The MKI$ and CVI processes mirror
each other: MKI$ converts a number into a format for storage in random
files and CVI converts the random file storage into a format that the
program can use.
When used with random access files, the LOC function returns the .. current
record number." The current record number is the last record number that
was used in a GET or PUT statement. For example, the following statement
ends the program execution if the current record number in file #1 is greater
than 50.
Program 6 - Inventory
OPEN"INVEN.DAT" AS #1 LEN=89
FIELD #1,1 AS F',80 AS D', 2 AS Q', 2 AS R', 4 AS P$
FunctionLabel:
CLS:PRINT"Functions:":PRINT
PRINT "1. Initialize file"
PRINT "2. Create a new entry"
PRINT "8. Display inventory for one part"
PRINT "4. Add to stock"
PRINT "5. Subtract from stock"
PRINT "6. Display all items below reorder level"
PRINT "7. Done with this program"
PRINT:PRINT:INPUT "Function";FUNCT
IF (FUNCT>O) AND (FUNCT<8) THEN GOTO Start
GOTO FunctionLabel
Start:
Most, but not all, word processing programs have a filing option called "text
only," "unformatted," or "non-document." When text is saved with this
option, aU the hidden control characters are removed. Only the text is filed.
Also, if you write a program in Amiga Basic and later wish to use a word
processor to edit it, prepare the program first. When you save the Amiga
Basic program, use the .. ,A" (ASCII) option in the SAVE statement, which
saves the program in a format that can be read by the word processing
program.
Advanced Topics
The Amiga library routines are machine language routines that are
automatically loaded into memory when you boot the machine. However, to
use a particular library's routine, you must first open that library. After
calling the routine from within your Amiga Basic program, you must be sure
to close the library.
Subprograms
First, subprograms use variables that are isolated from the rest of the
program. If you accidentally use the same variable name in a subprogram
and in the main program, the two variables still retain separate values.
Variables within subprograms are called local variables, because their values
cannot be changed by actions outside the subprogram.
The statements that make up the body of a subprogram are enclosed by the
SUB and END SUB statements. The EXIT SUB statement can be used to
exit a particular subprogram before it reaches the END SUB statement.
Execution of an EXIT SUB or END SUB statement transfers program
control back to the calling routine. The syntax is as follows:
END SUB
STATIC is a required keyword. It indicates that all the variables within the
subprogram retain their values between invocations of the subprogram.
Static variable values cannot be changed by actions taken outside the
subprogram. STATIC requires that the subprogram be non-recursive; that
is, it does not contain an instruction that calls itself or that calls a
subprogram that in turn calls the original subprogram.
All Amiga Basic statements can be used within a subprogram, except the
following:
• COMMON statements
• CLEAR statement
Shared Variables
The SHARED statement lets you use variables from the main program in a
subprogram (with their current values) without declaring them as arguments
in the CALL statement. The SHARED statement only affects variables
within that subprogram. For example:
END SUB
Static Variables
Amiga Basic assumes initial values of zero or null strings. If the subprogram
is exited and then reentered. however. variable and array values are those
present when the subprogram was exited.
Referencing Subprograms
the arguments are the variables SUBTOTAL and TAX, and the array
variable TOTAL.
The parameter values that transfer (in the manner described above)
between the main body of the program and the subprogram are said to be
passed by reference. This means that if the formal parameter is modified by
the subprogram, the argument's value also changes. For example:
CALL AddIt(A,B,C)
Suppose that when the program executes the CALL statement, A has a
value of 2 and B equals 3. When control returns to the main program, A
and B will have altered values, because the A variable is tied to X , and B to
Y. If the value of X is changed in the subprogram, the value of A is altered
accordingly. In this example, the value of A is increased by 12 as a result of
the statement X = X + 12. This subtle change happened because the
variable X is an "alias" for the variable A.
When you don't want the values of variables in the main program to change
in the subprogram, put parentheses around the variables. Parentheses cause
these variables to retain their values, regardless of what happens in the
subprogram. For example:
The parentheses around the first two arguments force Amiga Basic to treat
them as expressions. This means that their values cannot be changed by
subprograms. You need not use parentheses to pass expressions that are not
simple variables. For example:
Note that the type of arguments must match the type of the formal
parameters or a type mismatch error results. For example:
CALL DoIt(l)
SUB DoIt(x) STATIC
CALL DoIt(l.O)
SUB DoIt(x) STATIC
DIM B(15)
A == 4
CALL SQUARE(A,B(3»
PRINT A,B(3)
END
Entire Arrays
You can give simple variable parameters any valid Amiga Basic name.
However, when you pass an entire array, it must be declared as a parameter
in the following form:
array-name ([number-oJ-dimensions])
where array-name is any valid Amiga Basic name for a variable and the
optional number-oJ-dimensions is an integer constant indicating the number
of dimensions in the array. Note that the actual dimensions are not given
here. For example,
END SUB
You can determine the upper and lower bounds of the dimensions of an
array by using the functions LBOUND and UBOUND.
Each function has two syntaxes: a general syntax and a shortened syntax
that can be used for one-dimensional arrays. The syntaxes are as follows:
The array is a valid Amiga Basic identifier and the dim argument is an
integer constant from 1 to the number of dimensions of the specified
array.
LBOUND and UBOUND are particularly useful for determining the size of
an array passed to a subprogram. See LBOUND in Chapter 8 for examples
of the use of array bound functions.
Expressions
the results printed would be 4 and 25. In this case (A) is passed as an
expression, and therefore the subprogram cannot change the value of A.
The following program example calls a simple machine language routine that
converts a string of text to uppercase and then prints the result. Preceding
the Amiga Basic program is a listing of the machine code, showing how the
stack is handled during the execution of the routine.
SECTION CODE
48E7 C080 MOVEM.L AO/DO-D1, - (SP) ; save registers
202F 0010 MOVE.L 16(SP) ,DO ; get length
206F 0014 MOVE.L 20{SP),AO ;Oet addr 1st byte $
4281 CLR.L D1 Clr high bytes D1
6000 001C BRA WhileTest ; 00 to loop test
StartLoop:
1230 0000 MOVE.B O(AO,DO) ,01 Oet next byte $
OC01 0061 CMP.B #'a' ,D1 If < 'a' •
6000 0010 BLT WhileTest
OC01 007A CMP.B #'z' ,01 or > 'z'
6EOO 0008 BOT WhileTest leave it alone
Parameters used by the routine are pushed onto the stack at the time the
routine is called. The parameters for routine CODE are pushed in the
following order:
Offsets:
string address (addr&) 8 (SP) (SP = Stack Pointer)
string length (length&) 4 (SP)
return address o (SP)
After registers AO, DO, and Dl are pushed. the stack status is as follows:
Offsets:
string address (addr&) 20 (SP)
string length (length&) 16 (SP)
return address 12 (SP)
AO 8 (SP)
Dl 4 (SP)
DO o (SP)
DIM code%(27)
FOR i = 0 TO 27
READ code%(i)
NEXT
Program 2 first reads the hexadecimal values that represent the compiled
code of the assembly language routine listed in Program 1. The length of the
data is 56 bytes; thus, the integer array code%O is dimensioned to 27
(4-byte) cells.
An INPUT statement prompts the user for a mixed case string, which
becomes the value of variable S$. The variable Ucase is aSSigned the
starting address of the array containing the routine. Amiga Basic then
assigns a temporary variable of the same name.
The routine checks for any lowercase letters. If found. lowercase letters are
replaced with their uppercase counterparts in the string. All other
characters are left alone. When the end of the string is reached, the routine
returns control to Amiga Basic. The program then prints the converted
string.
Event Trapping
Event trapping lets your program detect certain "events" and respond to
them by branching to an appropriate routine. The events that can be
trapped are: time passage (ON TIMER), mouse activity (ON MOUSE), the
selection of a custom menu item (ON MENU), a user's attempt to halt the
program (ON BREAK), and the collision of an animated object with another
object or the window (ON COLLISION).
To effect event trapping, you must include two special statements: the first
informs Amiga Basic where to transfer control when an event occurs, and
the second activates the event trap.
The general format for the ON ... GOSUB statement that specifies flow of
control in event trapping is as follows:
TIMER The timer is the Amiga's internal clock. If you use timer
event trapping, you can force an event trap every time a
given number of seconds elapses.
MOUSE Mouse event trapping lets you redirect program flow when
the user clicks the mouse.
MENU Menu event trapping lets you use the selection of custom
menu items to redirect program flow.
ON <eventspecifier> GOSUB 0
To activate event trapping for the specified event, use the statement:
<eventspecifier> ON
When the eventspeci/ier is OFF, no trapping takes place. The event is not
remembered.
Note: Once an error trap takes place, all trapping of a particular event is
automatically disabled until a RESUME statement is executed.
Memory Management
• The stack
• Amiga Basic's data segment
• The heap
The amount of RAM remaining (Total - (data segment + stack size» is the
RAM reserved for the heap. Using the CLEAR statement, you can allot the
space your program requires for the three adjustable areas of RAM.
The Stack
Certain Amiga ROM calls require a considerable amount of stack space. The
deeper you nest in your control structures, the more stack space is required
to execute a program. If you specify the stack size in a CLEAR statement,
the value must be at least 1024.
Amiga Basic's data segment holds the text of the program currently in
memory. It also contains numeric variables and strings. In addition, the
data segment contains file buffers for opened files.
Amiga Basic automatically gets a data segment size of 25000 bytes. If you
have a small program to run and wish to run other Amiga tasks while your
program executes, simply execute a CLEAR statement with a smaller data
segment size.
If your program is tight for memory, there are a number of ways you can
conserve memory. A sequential file buffer has a default size of 128 bytes.
Thus, one memory conservation technique is to define a smaller sequential
file buffer. A smaller buffer may slow execution of an I/O intensive
program, however. See OPEN in Chapter 8 for details on changing a
sequential file's buffer size.
Additionally, the kind of numeric variables you use will have an effect on
data segment space. Integer variables take half the number of bytes of single
precision; single-precision take half the number of bytes of double
precision. Also, chaining several small programs together uses less memory
than loading and running a large program that incorporates all the smaller
ones.
Amiga Basic shares the System Heap with other tasks running on the Amiga.
The LIBRARY, WINDOW, and SCREEN statements all consume memory
from the heap.
The system heap also contains the buffer for SOUND and WAVE
information. When used, this buffer takes up 1024 bytes of RAM. Heap
space can be kept smaller by releasing the SOUND/WAVE buffer with a
WAVE 0 statement when it is no longer needed.
While you develop a program, you can keep track of your program's stack
size and data segment size and system heap requirements by using the FRE
function. The FRE function takes the following two forms:
FRE(n)
FRE( II ")
2. If (n) is -2, the function returns the number of bytes never used
by the stack. This does not return the number of free bytes
available in the stack. It is used in testing programs to fine-tune
the stack-size parameter of the CLEAR statement.
3. If (n) is any number other than -1 or -2, or if you use the FRE
(" ") function, Amiga Basic returns the number of free bytes
available in Amiga Basic's data segment.
Library routines are special Amiga resource files that are bound to Amiga
Basic dynamically at run time. You use the CALL statement to execute one
of the library routines, in a manner similar to executing your own assembly
language routines. Parameters are passed by value using standard
C-Ianguage conventions. To access a library routine, you must first open
the library that contains that routine.
Opening a Library
There are several libraries available for use in your Amiga Basic
applications, each containing a varying number of special routines.
Associated with each routine is a special "how-to" file that describes the
parameters that routine takes and which registers must be used. These
special files are called .fd files. You'll find a complete list of the information
they contain in the Amiga ROM Kernel Manual.
The Extras disk contains some of the .bmap files for the libraries. You can
find the complete set of .fd files on the Amiga Macro Assembler disk or the
Amiga C disk. Once the .fd files are on your disk, you must use ConvertFD
to convert them to .bmap files.
You open a library with the LIBRARY statement. Assuming your disk
contains the appropriate .bmap files, the LIBRARY statement puts all of that
library's routines at your program's disposal. As many as five libraries can
be open at one time.
Calling a Function
Once the library is open, its routines can be called in a manner similar to
subprograms or your own machine language routines. If your application
expects a returned function value, however, you must inform Amiga Basic of
the value's type (for example, long integer, denoted by a trailing declaration
character &) in a DECLARE FUNCTION statement.
enable% = AskSoftStyle&(WINDOW(8»
Font "topaz.font",8,O,O
FOR i=O to 4
A
SetStyle CINT(2 i)
NEXT i
Several other graphics.library routines are also used in the example. each
with a list of the parameters Amiga Basic is passing to it. Each of the library
routines is described in the Amiga ROM Kernel Manual.
Most library routine calls can be made as in the preceding program example.
However. if the routine call follows ELSE or THEN in a statement. you must
explicitly use the CALL keyword to distinguish the routine from a label.
For example:
Amiga Basic implements the animation facilities built into the Amiga system
through program statements and the Object Editor. The COLLISION and
OBJECT statements (described in Chapter 8) manipulate images in the
output window. The Object Editor defines these images (or objects. as they
are referred to throughout this book).
• draw free-form across the canvas with the Object Editor pen
• select colors that form the borders of the object you create
After creating an object, you save it in a file whose name you specify; the file
contains the static attributes (including the size, shape, and color) of the
object. To animate the object from a program, open the file. read the
contents as a string. and then use the OBJECT. SHAPE to define the object
to your program. For an example of statements that do this. see the
OBJECT.SHAPE description in Chapter 8 of this manual.
Note: The Object Editor assigns attributes to objects to ensure that. during
program execution. they collide both with each other and with the border of
the window. You can change this initial setting using an OBJECT. HIT
statement (described in Chapter 8) in your program.
This section explains the layout of the Object Editor window (shown below),
where you create your objects.
Menu Bar
Three menus are available: File, Tools, and Enlarge. The File menu lets
you save and retrieve the object files you create. The Tools menu provides
several methods of creating images. The Enlarge menu lets you expand
your object for fine details. These menus are described in the next section.
Canvas
The Canvas, located in the upper lefthand comer, is where you create and
color (as well as erase) objects.
If you are creating a sprite (a sprite is one of two types of objects you can
create, and is described later in this chapter), you cannot increase the width
beyond the size displayed (16 pixels, from 0 to 15); you can, however,
increase the height.
The Color Choice Bar lets you change the paint and border colors for
objects. To change the color, move the pointer over the desired color and
click the Selection button. The characters in the word Color that appear
next to the bar change to the color you select.
The number of color choices in the Choice Bar depends on the depth of the
screen, as determined by the depth parameter in the program's SCREEN
statement (see Chapter 8 for a description of this statement).
To create objects with more than four colors, change the ObjEdit program
(comments are included in the program listing to help you do this). See
"How to Increase Screen Depth, OJ below.
Status Line
To the left are the X and Y coordinates; they indicate the current size (in
pixel coordinates) of the canvas. Next, the current Tools selection item
(Pen, Oval, Line, Rectangle, Paint. or Eraser) appears.
New Erases the screen and restores the canvas to its original
dimensions if they have been changed.
Open Prompts you for the name of an existing file. Specify the
name of any file previously created through the Object
Editor and press RETURN.
Save Saves the file under the same name as it was opened. The
Object Editor prompts you for a file name if you previously
chose New. Enter the name and press RETURN.
Quit Causes an exit from the Object Editor and returns you to
Amiga Basic.
Item Function
Item Function
The Amiga system recognizes two types of objects; Amiga terminology refers
to these objects as sprites and bobs. The Object Editor prompts you to
select either a sprite or a bob before you can define the object. Therefore.
you must be aware of the differences between these two object types before
defining one. (If you are already familiar with these differences, skip to the
next section of the chapter.)
The following table summarizes the major difference between sprites and
bobs:
Bobs Sprites
For details on bobs and sprites. see the Graphics Animation Routines
chapter in the Amiga ROM Kernel Manual.
The Object Editor resides on the Extras disk in the BasicDemos drawer
under the name ObjEdit. You open the editor and start operations just as
you would any other Amiga Basic program. (Chapter 2 gives the steps to
achieve this.) Then, follow the steps listed below.
Note: If you use a 256K machine, drag the Object Editor icon out of the
BasicDemos window. Then close all windows and click on the Object Editor
icon. This frees a maximum amount of memory for using the Object Editor.
If you wish to load the Objedit program from within Basic, use the file
name "basicdemos/objedit". Also, change the line with the LIBRARY
statement from LIBRARY "graphics.library" to LIBRARY
":basicdemos/graphics.library" .
3. From the Tools menu, choose how you want to create the
image: drawing free-form with the pointer, or by drawing an
oval, rectangle, or line. Choose Erase to remove any part of the
object.
You can use output from other graphic editing sources with the Amiga Basic
OBJECT statements if you wish. Below is a description of the file format for
objects saved by ObjEdit (and, therefore, that expected by the OBJECT
statements that control animation).
Word# (32-bit)
(16-bit)
last
datal -
Sequential byte values of image: upper-left to lower-right of
plane 1, upper-left to lower-right of plane 2, ... upper-Ieft to
lower-right of plane n in depth of n
data2 -
Image-shadow bit plane (unused unless bit 2 of word A is set)
data3 -
Collision bit-plane (unused unless bit 1 of word A is set)
D - Six bytes for sprite colors if bit 0 of word A is set. (Only first
four bytes are used)
The ObjEdit program uses a screen depth of 2, allowing you a choice of only
the background color and three other colors. If your program's memory
requirements allow, you can create animation objects with a greater color
variation. The animation program that uses these objects must have a
screen depth that matches the depth used in creating the object.
In the ObjEdit program, you'll find instructions for increasing the display
depth. The comments include program lines from which you can remove
the apostrophe to make them execute. These are as follows:
The above lines set variables DEPTH and scrn, then use these variables to
open a custom screen and a window within that screen. When you activate
these lines and then create an object within the custom screen that results.
your animation object is saved complete with the information about that
screen.
Therefore, it is important to make sure that the program that controls your
animation also creates a screen whose depth is three. Remember that you
can only create bobs. not sprites. in a screen depth greater than two.
Reference 8-1
Character Set
The Amiga Basic character set is composed of alphabetic, numeric, and
special characters. These are the only characters that Amiga Basic
recognizes. There are many other characters that can be displayed or
printed, but they have no special meaning to Amiga Basic.
The Amiga Basic alphabetic characters include all the uppercase and
lowercase letters of the American English alphabet. Numeric characters are
the digits 0 through 9. The following list shows the special characters that
are recognized by Amiga Basic.
Blank
= Equal sign or assignment symbol
+ Plus sign
Minus sign
• Asterisk or multiplication symbol
I Slash or division symbol
Up arrow or exponential symbol
( Left parenthesis
) Right parenthesis
% Percent sign
# Number (or pound) sign
$ Dollar sign
I Exclamation point
[ Left bracket
] Right bracket
Comma
Period or decimal point
Single quotation mark (apostrophe)
Semicolon
Colon
& Ampersand
? Question mark
< Less than
> Greater than
\ Backslash or integer division symbol
8-2 Reference
Character Name or Function
@ At-sign
Underscore
RETURN Terminates input of a line
" Double quotation mark
The following list shows the Amiga-key characters that are used in Amiga
Basic.
or
The nnnnn (which specifies the line number) must be an integer between 0
and 65529.
Reference 8-3
The alpha-num-label is any combination of letters, digits, and periods that
starts with a letter and is followed (with no intervening spaces) by a colon
(:) .
As you can see. Amiga Basic program lines can begin with a line number. an
alphanumeric label. neither, or both. and must end with a carriage return. A
program line can contain a maximum of 255 characters. More than one
Amiga Basic statement can be placed on a line, but each must be separated
from the last by a colon. Program lines are entered into a program by
pressing the Return key. This carriage return is an invisible part of the line
format.
Line numbers and labels are pointers used to document the program (make
it more easily understood) or to redirect program flow. as with the GOSUB
statement.
If. for example. you want a specific part of a program to run only when a
certain condition is met. you could write the following program:
The interpreter searches for a line with the label Design: and executes the
subroutine beginning with that line. Note that no colon is needed for Design
in the GOSUB statement.
Note: Amiga Basic executes each line you enter sequentially regardless of
the line number you assign. You should be aware of this if you are
accustomed to using another BASIC that sorts the lines sequentially before
execution.
8-4 Reference
Label Definitions
Alphanumeric line labels can contain from 1 to 40 letters. digits, or periods.
They must begin with an alphabetical character. This allows the use of
mnemonic labels to make your programs easier to read and maintain.
For example, the following line numbers and alphanumeric labels are valid:
100 ALPHA:
65000 A16:
SCREEN.SUB:
Restrictions
ON ERROR OCTO 0
does not branch to line number 0 if an error occurs. Instead. error trapping
is disabled by this statement.
Warning: Line numbers are used only as labels. Amiga Basic does not sort
them or remove duplicates.
Reference 8-5
Format
A label, a line number, or both a label and a line number can appear on any
line. The line number, when present, must always begin in the leftmost
column. A label must begin with the first non-blank character following the
line number (if present) and end with a colon; a blank cannot exist between
the label and the colon.
Constants
Constants are the actual values Amiga Basic uses during program execution.
There are two types of constants: string and numeric. A string constant is a
sequence of alphanumeric characters enclosed in double quotation marks.
String constants may be up to 32,767 characters in length.
Numeric constants are positive or negative numbers. There are five types of
numeric constants:
8-6 Reference
Floating-point Positive or negative numbers represented in
exponential form (similar to scientific notation).
A floating-point constant consists of an
optionally signed integer or fixed-point number
(the mantissa) followed by the letter E and an
optionally signed integer (the exponent).
(Double precision floating-point constants are
denoted by the letter D instead of E.)
Reference 8-7
The following are examples of numeric constants:
46.8 345692811
-1.09E-6 -1.09432D-06
3489.0 3489.0#
22.51 7654321.1234
Variables
Variable Names
Variable names are not case-sensitive. That means that variables with the
names ALPHA, alpha, and AlPhA are the same variable.
8-8 Reference
Reserved Words
Reserved words are words that have special meaning in Amiga Basic. They
include the names of all Amiga Basic commands, statements, functions, and
operators. Examples include GOTO, PRINT, and TAN. Always separate
reserved words from data or other elements of an Amiga Basic statement
with spaces. Reserved words cannot be used as variable names. Reserved
words can be entered in either uppercase or lowercase. A complete list of
reserved words is given in Appendix C, "Amiga Basic Reserved Words."
The dollar sign is a variable type declaration character; that is, it "declares"
that the variable will represent a String.
The trailing declaration characters for numeric variables and the memory
requirements (in bytes) for storing each variable type are as follows:
Reference 8-9
% SHORT Integer 2
& LONG Integer 4
I Single precision 4
# Double precision 8
$ String 5 bytes plus the contents of the
string.
Array Variables
8-10 Reference
Type Conversion
When necessary, Amiga Basic will convert a numeric constant from one type
to another. Keep the following rules in mind.
• Arithmetic
• Relational
• Logical
• Functional
Reference 8-11
Hierarchy of Operations
The Amiga Basic operators have an order of precedence; that is, when
several operations take place within the same program statement, certain
operations are executed before others. If the operations are of the same
level, the leftmost one is executed first, the rightmost last. The following is
the order in which operations are executed:
1. Exponentiation
2. Unary Negation
3. Multiplication and Floating-Point Division
4. Integer Division
S. Modulo Arithmetic
6. Addition and Subtraction
7. Relational Operators
8. NOT
9. AND
10. OR and XOR
11. EQV
12. IMP
Arithmetic Operators
The Amiga Basic arithmetic operators are listed in the following table in
order of operational precedence:
Exponentiation XAy
Unary Negation -X
• Multiplication X·Y
I Floating-Point Division XIY
\ Integer Division X\Y
MOD Modulo Arithmetic YMODZ
+. - Addition. Subtraction X+Y, X-Y
8-12 Reference
To change the order in which the operations are performed. use
parentheses. Operations within parentheses are performed first. Inside
parentheses. the usual order of operation is maintained.
X-z
y (X - z) / y
Xy
Z X*y/z
X+Y
Z (X + Y) I Z
yZ
X
X(-Y) X*(-Y)
Integer Division
Integer division is denoted by the backslash (\) instead of the slash (/); the
slash indicates floating-point division. The operands of integer division are
rounded to integers (for short integers. in the range -32768 to +32767 and
for long integers. from -2147483648 to 2147483647) before the division is
performed. and the quotient is truncated to an integer.
Reference 8-13
For example:
X=10/4
Y=25.68\6.99
PRINT X.Y
2 8
Modulo Arithmetic
For example:
Note that Amiga Basic rounds both the divisor and the dividend to integers
for the MOD operation.
Relational Operators
Relational operators are used to compare two values. The result of the
comparison is either "true" (-1) or "false" (0). This result can then be used
to make a decision regarding program flow (see the "IF ... THEN" statement
8-14 Reference
in the Statement and Function Directory). The following table lists the
relational operators:
= Equality X=Y
<> Inequality X<>Y
< Less than X<y
> Greater than X>Y
<= Less than or equal to X <= Y
>= Greater than or equal to X >= Y
(The equal sign is also used to assign a value to a variable. See "LET" in
the Statement and Function Directory.) When arithmetic and relational
operators are combined in one expression, the arithmetic operation is always
performed first.
Logical Operators
Reference 8-15
Operation Value Value Result
NOT X NOT X
T F
F T
AND X Y XANDY
T T T
T F F
F T F
F F F
OR X Y X ORY
T T T
T F T
F T T
F F F
XOR X Y XXORY
T T F
T F T
F T T
F F F
IMP X Y X IMP Y
T T T
T F F
F T T
F F T
EQV X Y X EQVY
T T T
T F F
F T F
F F T
8-16 Reference
If· both operands are supplied as 0 or -1. logical operators return 0 or -1,
respectively. The given operation is performed on these integers in bits; that
is, each bit of the result is determined by the corresponding bits in the two
operands. Thus. it is possible to use logical operators to test bytes for a
particular bit pattern. For instance. the AND operator can be used to
"mask" all but one of the bits of a status byte. The OR operator can be used
to "merge" two bytes to create a particular binary value. The following
examples illustrate how the logical operators work:
Reference 8-17
See the Statement and Function Directory starting on page 8-19 for exact
description of individual intrinsic functions and DEF FN.
Concatenation
Combining two strings together is called concatenation. The plus symbol (+)
is the concatenation operator. Here is an example of the use of the
operator:
Filename
New Filename
This example combines the string variables A$ and B$ to produce the value
"Filename. "
Relational Operators
Strings can 'also be compared using the same relational operators that are
used with numbers:
8-18 Reference
Using operators with strings is similar to using them with numbers, except
that the operands are strings rather than numeric values. String comparisons
are made by taking one character at a time from each string and comparing
the ASCII codes. The ASCII code system assigns a number value to each
character produced by the computer. (See Appendix A, "ASCII Character
Codes. ") If all the ASCII codes are the same, the strings are equal. If the
ASCII codes differ t the lower code number precedes the higher. If during
string comparison the end of one string is reached, the shorter string is said
to be smaller if they are equal to that point. Leading and trailing blanks are
significant.
Syntax Conventions
Amiga Basic is a powerful programming language with over 130 statements
and functions. These are presented in alphabetical order on the following
pages.
The correct syntax for each statement or function is given after the name.
There are two kinds of syntax: one for statements and one for functions. All
Reference 8-19
functions return a value of a particular type and can be used wherever an
expression can be used. Unlike functions, statements can appear alone on
an Amiga Basic program line or they can be entered in immediate mode
where they are considered commands.
8-20 Reference
ABS ABS(X)
Example:
The following example shows the results ABS returns for a positive and a
negative number.
987 987
The parameters x and y specify one of several points that Amiga Basic is to
connect in forming a polygon with an AREA FILL statement. The
AREA FILL statement ignores all AREA statements in excess of 20.
If STEP is included, x and yare offsets from the current graphics pen
position. Otherwise, they are absolute values specifying a location in the
current window.
Reference 8-21
The mode parameter determines the format of the polygon as shown in the
following table.
o Fills the area with the area pattern established by the PATTERN
statement. This is the default mode.
Example:
AREA (10,10)
AREA STEP (0.40)
AREA STEP (40.-40)
AREAFILL
ASC ASC(X$)
Returns a numerical value that is the ASCII code for the first character of
the string X$.
The Amiga Basic character set includes the entire ASCII set, but also
contains additional characters. These non-ASCII characters, as well as the
standard ASCII characters, may be tested with the ASC function (see
Appendix A, "ASCII Character Codes").
Example:
8-22 Reference
LET OBJECT$ 2 "T"
PRINT ASC(OBJECT$)
END
84
ATN ATN(X)
Examples:
Enter a number 33
Arc tangent of 33 is 1.540503
If you have another number, enter y y
Enter a number 2
Arc tangent of 2 is 1.107149
If you have another number. enter y n
Reference 8-23
BEEP BEEP
Example:
BREAK ON BREAK ON
BREAK OFF BREAK OFF
BREAK STOP BREAK STOP
8-24 Reference
Example:
BREAK ON
ON BREAK GOSUB DIRECTUSER
DIM PAYTIME(99),HRS(99),GROSS(99),FIT(99).FICA{99),STATE(99) ,NET(99)
LET TOTALEMPLOYEES = 99
OPEN "0",#1, "EmployeePay"
FOR I=l TO TOTALEMPLOYEES
WRITE#l,PAYTIME(I),HRS(I),GROSS(I),FIT(I).FICA{I),STATE(I).NET(I)
NEXT I
CLOSE #1 :BREAK OFF
INPUT "Do you wish to print the payroll now (YIN)?". ANSWER$
IF ANSWER$ = "yn THEN BREAK ON: GOSUB PRINTCHECKS
END
DIRECTUSER:
CLS:BEEP:PRINT "You can't exit program until file is updated."
RETURN
(1) Calls an Amiga Basic subprogram as defined by the SUB statement; (2)
calls a machine language routine at a fixed address; or (3) calls a machine
language LIBRARY routine.
You can call subprograms using the SUB statement. Variables are passed by
reference. Expressions are passed by value. For example.
Reference 8-25
See the SUB statement in this chapter and also in Chapter 6 for more
information on calling subprograms.
The CALL statement is the only way to transfer program flow to an external
subroutine. The name identifies a simple variable that contains an address
that is the starting point in memory of the subroutine. The name cannot be
an array element.
The argument list contains the arguments that are passed to the subroutine.
Parameters are passed by value using the standard C-Ianguage calling
conventions. All parameters must be short integer or long integer, or Amiga
Basic issues a "Type mismatch" message. The address of a single or double
precision variable can be passed as follows:
CALL Routine(VARPTR(x»
CALL Routine(SADD(x$»
In the following example, the variable that holds the address of the routine is
a short integer (&). (Use a long integer if the address length is 24 bits; a
short integer or a single-precision number can't hold a 24-bit address.)
a=O: b=O
DIM Code%(100)
FOR 1=0 TO 90
READ Code% ( I )
NEXT I
CodeAdr& = VARPTR(Code%(O»
CALL CodeAdr&(a,b)
Library routines are machine language routines that are bound to Amiga
Basic dynamically at runtime.
8-26 Reference
Parameters are passed by value using standard C-Ianguage conventions.
Example:
In the above example, Amiga Basic creates a variable by the name of Draw.
It then stores information about where the machine language routine resides
in this variable. For this reason, the variable cannot be a short integer.
For example. the following call would generate a "Type mismatch" error
DEFINT A-Z
CALL Draw(50,60)
DEFINT A-Z
CALL Draw#(50,60)
Note that Amiga Basic ignores the trailing declaration character (#)
following the routine name when searching the libraries for the routine. So,
in the above example, it would search for "Draw," and not "Draw#."
Warning
Because the word CALL can be omitted, a CALL can be executed with the
syntax
name argument-list
ALPHA: Let A = 5
Reference 8-27
It is not visually clear whether the statement is calling a subprogram named
ALPHA with no argument list, or the statement LET A = 5 is on a line with
the label ALPHA:. In such a case, ALPHA: is assumed to be a line label
and not a subprogram call with no arguments.
CDBL CDBL(X)
Example:
AI = 6666 : B! = 1000001
PRINT A!*B!, "(result printed in single precision)"
PRINT CDBL(AI*B!), "(result printed in double precision)"
8-28 Reference
the called program. If it is omitted. execution begins at the first line. An
alphanumeric label cannot be used as a starting point.
The MERGE option allows a subroutine to be brought into the Amiga Basic
program as an overlay. That is, the current program and the called program
are merged. with the called program being appended to the end of the
calling program. The called program must be an ASCII file if it is to be
merged.
With the ALL option, every variable, except variables which are local to a
subprogram in the current program, is passed to the called program. If the
ALL option is omitted, the current program must contain a COMMON
statement to list the variables that are passed.
If the ALL option is used and the expression is not, a comma must hold the
place of the expression.
Note: The CHAIN statement with the MERGE option preserves the current
OPTION BASE setting.
Reference 8-29
The DELETE range consists of a line number or label, a hyphen, and
another line number or label. All the lines between the two specified lines,
inclusive, are deleted from the program chained from.
Example:
This program illustrates the use of the CHAIN and COMMON statements.
Changes the current directory. The string is an expression that identifies the
new directory that becomes the current directory.
Example:
Returns a string whose one character has the ASCII value given by I (see
Appendix A, "ASCII Character Codes").
8-30 Reference
Example:
CLS
FOR I = 65 TO 90
PRINT CHR$(I); SPC(l);
NEXT I
ABC D E F G H I J K L M N 0 P Q R STU V W X Y Z
CINT CINT(X)
Note: For a decimal portion that is exactly .5, if the integer portion of X is
even, the function rounds down. If it is odd, the function rounds up.
Example:
PRINT CINT(-S.5)
PRINT CINT(-S.2)
FOR I = 1 TO S
X = RND*10
PRINT X. "= random number generated by RND, times 10"
PRINT CINT (X), "= integer portion of the same number"
NEXT I
Reference 8-31
The following is displayed on the screen:
-4
-3
1.213501 random number generated by RND. times 10
1 integer portion of the same number
6.518611 = random number generated by RND. times 10
7 integer portion of the same number
8.686811 random number generated by RND. times 10
9 integer portion of the same number
The STEP option indicates the x and y coordinates are relative to the
current coordinates of the pen. For example. if the most recent point
referenced were (10.10), CIRCLE STEP(20,15) would reference a point 30
for x and 25 for y.
The radius is the radius of the circle in pixels. The color-id specifies the
color to be used; it corresponds to the color-id in a PALETTE statement.
The default color is the current foreground color as set by the COLOR
statement.
The start and end parameters are the start and end angles in radians. The
range is -2· (Pi) through 2· (Pi). These angles allow the user to specify
where a circle or ellipse begins and ends. If the start or end angle is
negative, the circle or ellipse is connected to the center point with a line,
and the angles are treated as if they were positive. The start angle may be
less than the end angle.
The aspect is the aspect ratio, which is the ratio of the width to the height of
one pixel. The aspect ratio used by manufacturers of monitors varies.
8-32 Reference
CIRCLE draws a perfect circle if aspect is set to the aspect ratio of the
monitor; otherwise, CIRCLE draws an ellipse.
The aspect ratio for the standard Amiga monitor (using high resolution and
the 640 by 200 screen) is 2.25:1 or approximately .44 (112.25), which is the
default for aspect. If you specify .44 for aspect, or omit a specification. a
perfect circle is drawn on the Amiga monitor.
Example:
CIRCLE (60,60),55
The above example draws a circle with a radius of 55 pixels; the center of
the circle is located at x coordinate 60 and y coordinate 60.
The above example draws a series of ellipses of varying aspect ratios. The 0
parameter specifies the color; here, the Amiga system background color of
blue would apply unless overridden by a PALETTE statement.
Sets all numeric variables to zero and all string variables to ".. and allocates
memory to the Amiga Basic data area and to the system stack. Closes all
files and resets all DEF FN, DEFINT. DEFLNG, DEFSNG. DEFDBL, and
DEFSTR statements.
Reference 8-33
stack is a numeric expression that specifies the amount of memory to be
allocated to the system stack; the numeric expression must be 1024 bytes or
greater. If this parameter is omitted, Amiga Basic allocates the current
value.
Examples:
CLEAR
CLEAR ,130000
CLEAR, ,2000
CLEAR .20000,2048
Note: For a decimal portion that is exactly .5, if the integer portion of X is
even, the function rounds down. If it is odd, the function rounds up.
The fUenumber is the number with which the file was opened. A CLOSE
with no arguments closes all open files. The association between a particular
file and the file number terminates upon execution of a CLOSE statement.
The file may then be reopened using the same or a different filenumber;
likewise, that filenumber can be reused to open any file.
A CLOSE for a sequential output file writes the final buffer of output. When
Amiga Basic performs sequential file I/O, it uses a holding area, called a
8-34 Reference
buffer, to build a worthwhile load before transferring data. If the buffer is
not yet full, the CLOSE statement assures that the partial load is transferred.
The END, SYSTEM, and CLEAR statements and the NEW command
always close all disk files automatically. (STOP does not close disk files.)
Example:
This is a fragment of a program that opens an existing file, gets data from it,
updates it, and returns it.
CLS CLS
Erases the contents of the current Output window and sets the pen position
to the upper left-hand corner of the Output window.
The CLS statement clears the current Output window only and not other
Output windows.
Example:
CLS
Reference 8-35
COLLISION COLLI SION (object-id)
Amiga Basic maintains a queue of collisions that have occurred and have not
yet been reported to the program. Amiga Basic can remember only 16
collisions at one time. After the sixteenth collision, it discards any new
collision information. Each call of COLLISION removes one item from this
queue of collisions.
If the function returns a negative number from -1 through -4, the object-Id
collided with one of the four window borders, as indicated below.
-1 Top border
-2 Left border
-3 Bottom border
-4 Right border
COLLISION ON COLLISION ON
COLLISION OFF COLLISION OFF
COLLISION STOP COLLISION STOP
8-36 Reference
with another object or the window border. Use the COLLISION function to
determine which object collided.
Reference 8-37
Example:
PALETTE 1,RND,RND,RND
PALETTE 2,RND,RND.RND
COLOR 1.2
The same variable cannot appear in more than one COMMON statement.
Array variables are specified by appending parentheses (that is "( )") to the
variable name. If all variables are to be passed, use CHAIN with the ALL
option and omit the COMMON statement.
Some versions of Amiga Basic allow the number of dimensions in the array
to be included in the COMMON statement. This implementation accepts
that syntax, but ignores the numeric expression itself.
Example:
This program illustrates the use of the CHAIN and COMMON statements.
8-38 Reference
CONT CONT
Execution resumes at the point where the break occurred. If the break
occurred after a prompt from an INPUT statement, execution continues
with the reprinting of the "7" prompt or the prompt string).
CONT is invalid if the program has been edited during the break.
Example:
This example illustrates the use of the CONT and STOP statements.
Reference 8-39
Example:
COSINE OF 1 IS .5403023
COSINE OF 100 IS .8623189
COSINE OF 1000 IS .5623791
CSNG CSNG(X)
Example:
AN ~ 6666 : BN ~ 100000
PRINT AN*BN. "(result printed in double precision)"
PRINT CSNG(AN*BN). "(result printed in single precision)"
8-40 Reference
CSRLIN CSRLIN
Returns the approximate line number (relative to the top border of the
current Output window) of the pen.
In determining the line number, CSRLIN uses the height and width of the
character "0" as determined by the font of the current Output window. This
value is always greater than, or equal to, 1.
CSRLIN is the opposite of the LOCATE statement, which positions the pen.
Example:
The following example records the current line and row numbers, moves the
cursor to the bottom of the screen, and prints a message; it then restores the
cursor to its original position and prints a message.
Converts random file numeric string values to numeric values. CVI converts
a 2-byte string to a short integer. CVI, converts a 4-byte string to a long
integer. CVS converts a 4-byte string to a single-precision number, and
CVD converts an 8-byte string to a double-precision number.
Reference 8-41
eVI, eVL, evs, and eVD can be used with FIELD and GET statements to
convert numeric values that are read from a random disk file, from strings
into numbers. Use the VAL function instead of eVI, eVL, or evs to
" return the numerical value of a string.
Example:
Stores the numeric and string constants that are accessed by the READ
statement.
The variable type (numeric or string) given in the READ statement must
agree with the corresponding constant in the DATA statement.
8-42 Reference
Example:
DIM PatternO%(3)
DIM Pattern1%(S)
DIM Pattern2%(S)
FOR I=O TO S
READ PatternO%(I)
READ pattern1%(I)
READ Pattern2%(I)
NEXT I
DATA &HAAAA, &H3SS3, &HFFFF
DATA &H5555. &H3S33, &HFFFF
DATA &HAAAA, &HSSSS. &HFFFF
DATA &H5555, &HS33S. &HFFFF
DATE$ DATE $
Example:
08-10-1985
Causes Amiga Basic to search all libraries opened with the LIBRARY
statement for the machine language function id in any expression within the
program.
Reference 8-43
See LIBRARY statement for details on opened libraries.
The id is any valid Amiga Basic identifier and can optionally contain one of
the following trailing declaration characters: (%, &, I, #). The id identifies
the name of the machine language function and the type of value it returns.
The param-list is a list of parameters for the function. This list is ignored by
Amiga Basic, but it is useful for documentation purposes.
If the function is found, Amiga Basic passes all parameters (if any) to the
function. The trailing declaration character (if any) of the id indicates the
type returned by the function. If the id doesn't have a trailing declaration
character, the standard type identifier rules apply. (See DEFINT for
standard type rules.) For example, ALPHA# returns a double-precision
result, BETA% returns an integer result. and so on.
See the CALL statement for a description of the conventions for passing
parameters.
Example:
This sets the variable VPA& to the value returned by the library function
ViewPortAddress&.
The name parameter must be a legal variable name with no spaces between
it and DEF FN. When specified in a program, name invokes the function
being defined.
8-44 Reference
The parameter-list contains the variable names in the function definition
that are to be replaced when the program invokes the function. Each name
must be separated by a comma. These variables contain the values specified
in the corresponding argument variables passed from the program function
call.
The DEF FN statement can define either numeric or string functions. The
function alwaysretums the type specified in the calling statement. However.
Amiga Basic issues a "Type mismatch" message if the data type specified in
the calling statement does not match the data type specified in the DEF FN
statement.
Note: If you specify the same DEF FN name twice, Amiga Basic uses the
last definition.
DEF FN statements apply only to the program in which they are defined. If
a program passes control to a new program with a CHAIN statement, a DEF
FN statement in the old program does not apply to the new program.
Example:
Reference 8-45
The following is an example of input and output when these statements are
executed.
Amiga Basic assumes that any variable name beginning with a letter specified
in letter-range to be one of the variable types shown below.
Statement Declaration
Variable Type Character
DEF type declarations apply only to the program in which they are declared;
they are reset upon exit from the program.
8-46 Reference
Example:
OEFLNG a-p,w
This statement causes any name beginning with any letter from a through p
and the letter w to be treated as long integers.
The DELETE statement works with both line numbers and alphanumeric
labels. If line does not exist, an "Illegal function call" error message is
generated.
Specifies the maximum values for array variable subscripts, and allocates
storage accordingly.
Use the DIM statement when the value of an array's subscript(s) must be
greater than 10; otherwise Amiga Basic issues a "Subscript out of range"
error message. The minimum value for a subscript is always 0, unless
otherwise specified with the OPTION BASE statement.
The DIM statement sets all the elements of the specified arrays to an initial
value of zero. The maximum number of dimensions allowed in a DIM
statement is 255; the number you can actually specify depends on the
amount of memory available.
Reference 8-47
If the array has already been dimensioned or referenced and that variable is
later encountered in a DIM statement, Amiga Basic issues a
"Redimensioned array" error message. To avoid this error condition, place
DIM statements at the top of a program so that they execute before
references to the dimensioned variable are made.
Example:
END END
EOF EOF(jilenumber)
Returns -1 (true) if the end of a sequential input file has been reached. Use
EOF to test for end-of-file while reading in data with an INPUT statement,
to avoid "Input past end" error messages.
When EOF is used with a random access file, it returns true if the last GET
statement was unable to read an entire record. It is true because it was an
attempt to read beyond the end of the file.
8-48 Reference
Example:
OPEN "I",#l,"INFO"
LINE INPUT #1, LONGS
PRINT LONGS
CLOSE #1
OPEN "I",#l,"INFO·
WHILE NOT EOF(l)
PRINT ASC(INPUTS(l,#l»;
LET C = C + 1: IF C = 10 THEN PRINT: LET C = 0
WEND
CLOSE #1
END
Example:
ERASE BobArray
ERR ERR
ERL ERL
Returns the error number and the line on which the error occurred.
Reference 8-49
If the line with the detected error has no line number, ERL will return the
number of the first numbered line preceding the line with the error. ERL
will not return line labels. The ERR and ERL functions are usually used in
IF ... THEN statements to direct program flow in an error-handling routine.
With the Amiga Basic Interpreter, if the statement that caused the error was
an immediate mode statement, ERL will return 65535.
See Appendix B, "Error Codes and Error Messages," for a list of the Amiga
Basic error codes.
Example:
errorfix:
IF (ERR=55) AND (ERL=90) THEN CLOSE#l:RESUME
The value of the integer-expression must be greater than 0 and less than
256. If the value of the integer-expression equals an error code already in
use by Amiga Basic (see Appendix B, "Error Codes and Error Messages"),
the ERROR statement causes the error message for the Amiga Basic error to
be printed (unless errors are being trapped).
To define your own error code, use a value that is greater than the highest
value used by an Amiga Basic error code. Use the highest values possible to
avoid conflicting with duplicate codes in future versions of Amiga Basic. You
can write an error handling routine to process the error you define.
8-50 Reference
If an ERROR statement specifies a code for which no error message has
been defined, Arniga Basic responds with an "Unprintable error" error
message. Execution of an ERROR statement for which there is no
error-handling routine causes an error message to be generated and
execution to halt.
Example:
ERROR 15
String too long
EXP EXP(X)
Example:
FOR I = 0 TO 5
PRINT EXP(I)
NEXT I
1
2.718282
7.589056
20.08554
Reference 8-51
FIELD FIELD [#Jfilenumber. fieldwidth AS string-variable ...
The total number of bytes allocated in a FIELD statement must not exceed
the record length that was specified when the file was created with OPEN.
Otherwise. a "Field overflow" error message is generated. (The default
record length is 128 bytes.)
Any number of FIELD statements may be executed for the same file. All
FIELD statements that have been executed will remain in effect at the same
time.
Note
Do not use a fielded variable name in an INPUT or LET statement. Once a
variable name is fielded. it points to the correct place in the random file
buffer. If a subsequent INPUT or LET statement with that variable name is
executed, the variable's pointer no longer refers to the random record
buffer, but to string space.
Example:
This is a fragment of a program that opens an existing file and fields it for
three variables.
8-52 Reference
See page 5-13 for a complete programming example that uses the FIELD
command.
If you omit string. the statement lists all files in the current directory. If
string contains a directory name, all files in that directory are listed. If
string contains a filename, it is listed if the file exists.
If string specifies a drive number, the statement lists all files in the current
directory of the disk on that drive. See the AmigaDOS User's Manual for
details on specifying files and their pathnames.
Example:
FILES "df'l:"
FILES "CO
Example:
The following example shows the operation of FIX and INT on the same
negative, non-integer number.
30 PRINT FIX(-58.75)
40 PRINT INT(-58.75)
Reference 8-53
The following is displayed on the screen:
-58
-59
The program lines following the FOR statement are executed until the
NEXT statement is encountered. Then the counter variable is adjusted by
the amount specified by STEP. A check is performed to see if the value of
the counter is now greater than the final value of y. If it is not greater,
Amiga Basic branches back to the statement after the FOR statement and
the process is repeated. If it is greater, execution continues with the
statement following the NEXT statement. This is called a FOR ... NEXT
loop.
Nested Loops
FOR ... NEXT loops may be nested; that is, a FOR ... NEXT loop may be
placed within the context of another FOR .. NEXT loop. When loops are
8-54 Reference
nested, each loop must have a unique variable name as its counter. The
NEXT statement for the inside loop must appear before that for the outside
loop.
The variable in the NEXT statement may be omitted, in which case the
NEXT statement matches the most recent FOR statement. If a NEXT
statement is encountered before its corresponding FOR statement, a "NEXT
without FOR" error message is generated and execution is terminated.
Example:
o 10 20 80 40 50 60 70 80 90 100
FRE FRE(-I)
FRE(-2)
FRE( x)
FRE(-1) returns the total number of free bytes in the system. FRE (-2)
returns the number of bytes of stack space that has never been used.
FRE(x) where x is not -1 or -2 returns the number of free bytes in Amiga
Basic's data segment.
Example:
Reference 8-55
GET GET Wilfilenumberl [,recordnumber]
GET (xl,yl)-(x2,y2),array-name [(index [,index ... ,index])]
The two syntaxes shown above correspond to two different uses of the GET
statement. These are called a random file GET and a screen GET,
respectively.
In the first form of the statement, the file number is the number under which
the file was created with OPEN. If the recordnumber is omitted, the next
record (after the last GET) is read into the buffer. The largest possible
record number is 16,777,215.
After a GET statement has been executed, the data in recordnumber may be
accessed directly using fielded variables. (See "Random Access Files" in
Chapter 5, "Working With Files and Devices," for details on random file
operations.) INPUT# and LINE INPUT# also may be executed to read
characters from the random file buffer.
Screen GET
The second form of the GET statement is used for transferring graphic
images. GET obtains an array of bits from. the screen, and its counterpart,
PUT, places an array of bits on the screen.
8-56 Reference
The array-name is the name assigned to the place that will hold the image.
The array can be any type except string, and the dimension must be large
enough to hold the entire image.
Unless the array is of type integer, the contents of the array after a GET is
meaningless when interpreted directly (see below).
where x and yare the lengths of the horizontal and vertical sides of the
rectangle. D is the depth of the screen, for which 2 is the default.
It is possible to examine the x and y dimensions and even the data itself if an
integer array is used. The width, height, an depth of the rectangle can be
found in elements 0, 1, and 2 of the array, respectively.
The GET and PUT statements are used together to transfer graphic images
to and from the screen. The GET statement transfers the screen image
bounded by the rectangle described by the specified points into the array.
The PUT statement transfers the image stored in the array onto the screen.
Reference 8-57
Example:
GET (O,O)-(127,127),P
The line in the GOSUB statement is the line number or label of the first line
of a subroutine. Program control branches to the line after a GOSUB
statement executes. A RETURN within the GOSUB will return control back
to the statement just following the GOSUB statement in the program text.
A subroutine may contain more than one RETURN statement, should logic
dictate a return at different points in the subroutine.
8-58 Reference
GOSUB InitGraphics
InitGraphics:
iDraw = 30
iErase = 0
RETURN
It is advisable to use control structures (IF ... THEN ... ELSE, WHILE
... WEND, and ON ... GOTO) in lieu of GOTO statements as a way of
branching, because a program with many GOTO statements can be difficult
to read and debug.
Example:
CheckMouse:
IF MOUSE(O)=O THEN CheckMouse
IF ABS(X-MOUSE(l» > 2 THEN MovePicture
IF ABS(Y-MOUSE(2» < 3 THEN CheckMouse
MovePicture:
PUT(X.Y),P
X=MOUSE(l): Y=MOUSE(2)
PUT(X.Y).P
GOTO CheckMouse
HEX$ HEX$(X)
Reference 8-59
X is rounded to an integer before HEX$ (X) is evaluated.
Example:
FOR A = 10 TO 16
PRINT A ; HEX$(A)
NEXT A
10 A
llB
12 C
13 D
14 E
15 F
16 10
8-60 Reference
• If the result of the expression is true, the then-clause or GOTO
statement is executed.
The rules that apply to Syntax 1 and 2 also apply to Syntax 3. However,
Syntax 3 differs in the following respects:
Reference 8-61
• If no expressions are true, either (1) program execution
resumes at the first statement following the END IF statement or
(2) the ELSE statementBlock (if present) is executed and
program execution resumes at the first statement following the
END IF statement.
A block IF statement does not have to be the first statement on the line.
Example:
INPUT a,b
IF a = 1 THEN
IF b = 1 THEN
PRINT "a and bare 1"
ELSE
PRINT "a = l,b <> 1",
END IF
ELSEIF a > 0 THEN
IF b > 0 THEN PRINT "both a and b > 0"
REM---above line is single-line-IF, not Block-IF
PRINT "a > 0"
ELSE
PRINT "a <= 0"
PRINT ·we know nothing about b"
END IF
8-62 Reference
INKEY$ INKEY$
No characters are echoed. All characters are passed through to the program
except for Amiga-period, which terminates the program.
Note that if an Output window is not active while the program is running,
and the user presses a key, the key is ignored and a BEEP will occur, since
keystrokes on the Amiga are only directed to the selected window.
Example:
GetAKey:
a$=INKEY$
IF a$<> .... THEN
a$=UCASE$(a$)
IF a$="Y" THEN Response=l
IF a$="N" THEN Response=2
IF a$="C" THEN Response=3
IF Response=O THEN BEEP
END IF
IF Response = 0 THEN GOTO GetAKey
PRINT Response
Reference 8-63
The data that is entered is assigned to the variables given in the
variable-list. The number of data items supplied must be the same as the
number of variables in the list. Data items are separated by commas.
The variable names in the list may be numeric or string variable names
(including subscripted variables). The type of each data item that is input
must agree with the type specified by the variable name. (Strings input to an
INPUT statement need not be surrounded by quotation marks.)
Responding to INPUT with too many or too few items or with the wrong type
of value (string instead of numeric. etc.) causes the prompt message U?Redo
from start" to be generated. No assignment of input values is made until an
acceptable response is given.
Example:
The following example shows the use of INPUT to prompt a user to enter
values for a conversion program.
The following shows an example of some of the results displayed when a user
interacts with this program.
8-64 Reference
INPUTS INPUT$ (X[, [#lfilenumber])
If the keyboard is used for input, no characters are echoed on the screen.
All control characters are passed through except Ctrl-C, which is used to
interrupt the execution of the INPUT$ function.
Reads items from a sequential file and assigns them to program variables.
The filenumber corresponds to the number specified when the file was
created with OPEN. The variable-list contains the variable names to be
assigned to the items in the file; the data type specified for the variable
names must match the data type of the corresponding items in the file.
The data items in the file should appear just as they would if data were being
typed in response to an INPUT statement. Amiga Basic ignores leading
spaces, carriage returns, and linefeeds; it processes any other character as
the first digit of a number. For numeric items, the next space, carriage
return, linefeed, or comma delimits the last digit of the number from the
next item.
For string items, if the first character of a string is a quotation mark ("), a
second quotation mark delimits the end of the string (such a string cannot
contain an embedded quotation mark). If a quotation mark is not the first
character, then a comma, carriage return, linefeed, or the 255th character
of the string delimits the end of the string item.
Reference 8-65
INSTR INSTR([I.]X$,Y$)
Searches for the first occurrence of string Y$ in X$. and returns the position
at which the match is found. Optional offset I sets the position for starting
the search.
Example:
The following statements locate a specific field within a string and then
replace it with a new string; INSTR determines the byte location of the field.
INT INT(X)
Example:
PRINT INT(3.4)
X = INT(37.98)
PRINT INT(X)
Y = INT(-32.3)
PRINT INT(Y)
8-66 Reference
The following integers would be printed:
3
37
-3a
Example:
KILL "MailLabels"
The lower bounds are the smallest indices for the specified dimension of the
array. LBOUND returns 0 or 1 depending on whether the OPTION BASE
is 0 or 1.
Reference 8-67
Example:
LBOUND and UBOUND are particularly useful for determining the size of
an array passed to a subprogram. For example. a subprogram could be
changed to use these functions rather than explicitly passing upper bounds to
the routine:
LEFr$ LEFT$(X$,I)
Example:
The following routines shows the use of LEN in determining the offset of a
field within a string.
8-68 Reference
'THIS ROUTINE EXTRACTS THE ADDRESS a: FROM STRING RECORD$
Notice that the word LET is optional. The equal sign by itself is sufficient
for assigning an expression to a variable name.
Example:
1 2 3 1 2 3
Reference 8-69
LIBRARY LIBRARY "filename"
LIBRARY CLOSE
The filename is a string expression designating the file where Amiga Basic is
to look for machine language functions and subprograms. The LIBRARY
statement lets you attach up to five library files to Amiga Basic at a time.
Amiga Basic continues to look for subprograms in these libraries until a
NEW, RUN, or LIBRARY CLOSE statement is executed. See Appendix F
for more information on these statements.
The LIBRARY statement can generate the, "File not found" and the "Out
of memory" error messages.
To use the LIBRARY statement, you must create a .bmap file on disk; the
file describes the routines in the specified library. See Appendix F for a
description of how to create this file.
Example:
The coordinate for the starting point of the line is (xl,yl); the coordinate
for the end point of the line is (x2,y2).
8-70 Reference
With the .. ,b" option, a box is drawn in the foreground, with the points (xl,
y1) and (x2,y2) as opposite corners.
The .. ,bf" option fills the interior of the box. When out-of-range
coordinates are given, the coordinate that is out of range is given the closest
legal value. Boxes are drawn and filled in the color given by color-id.
With STEP, relative rather than absolute coordinates can be given. For
example, assume that the most recent point referenced was (10,10). The
statement LINE STEP (10,5) would specify a point at (20,15), offset 10
from xl; and offset 5 from yl.
If the STEP option is used for the second coordinate in a LINE statement, it
is relative to the first coordinate in the statement.
Example:
LINE(O.O)-(120.120) •• BF
The above statement draws a box and fills it in with the foreground color
specified by either the COLOR statement or the Amiga system default.
Reads an entire line from the keyboard during program execution and places
it in a string variable without using delimiters.
The "prompt-string" is a literal that Amiga Basic prints to the screen before
input is accepted. Amiga Basic prints question marks only when they the
are part of prompt-string. All input from the end of the prompt-string to
the carriage return is assigned to the string-variable.
Reference 8-71
To terminate a LINE INPUT statement, press the AMIGA key on the
righthand side of the keyboard and a period.
Example:
This example demonstrates the use of LINE INPUT and LINE INPUT#.
When you run this program, the following is displayed on the screen:
Reads an entire line from a sequential file during program execution and
places it in a string variable without using delimiters.
The file number corresponds to the number assigned to the file when it was
created with OPEN. The string-variable is the variable name to which
Amiga Basic assigns the line.
The carriage-return character delimits each line in the file. LINE INPUT#
reads only the characters preceding the carriage-return character, and then
skips this character and the linefeed character before reading the next line.
This statement is useful if each line in a data file is broken into fields, or if
an Amiga Basic program saved in ASCII format is being read as data by
another program.
8-72 Reference
Example:
• If only the first line is specified, that line and all following lines
are listed.
• If only the second line is specified, all lines from the beginning
of the program through the specified line are listed.
See also: "List Window Hints" in Chapter 4, "Editing and Debugging Your
Programs."
Example:
LIST
Reference 8-73
LLIST LLIST [line] [-[line]]
The options for LLIST are the same as for LIST, except that there is no
optional output device parameter; output is always to the printer (PRT:).
Loads a file from disk into memory. See SAVE for a description of file
specification that includes different drives or libraries.
If the filespec is not included, a requester appears to prompt the user for the
correct name of the file to load.
The filespec must include the filename that was used when the file was
saved.
The R option automatically runs the program after it has been loaded.
LOAD closes all open files and deletes all variables and program lines
currently residing in memory before it loads the designated program.
However, if the R option is used with LOAD. the program is run after it is
loaded, and all open data files are kept open. Thus, LOAD with the R
option may be used to chaiD. several programs (or segments of the same
program). Information may be passed between the programs using their
disk data files.
8-74 Reference
LOC LOC(jilenumber)
For random disk files, LOe returns the record number of the last record
read or written.
For sequential disk files, LOe returns a different number. the increment.
The increment is the number of bytes written to or read from the sequential
file. divided either by the number of bytes in the default record size for
sequential files (128 bytes) or the record size specified in the OPEN
statement for that file. Mathematically, this can be expressed as shown
below.
When a file is opened for sequential input. Amiga Basic reads the first
record of the file. so LOe returns 1 even before any input from the file
occurs. LOe assumes the filenumber is the number under which the file was
opened.
Positions the pen at a specified column and line in the current Output
window.
The value of the column and line parameters must be equal to or greater
than 1; the location they specify is relative to the upper-left comer of the
current Output window. If you omit these parameters, Amiga Basic uses the
current location of the pen.
In determining the column and line position. LOeATE uses the height and
width of the character "0" in the font of the current Output window.
Reference 8-75
Example:
The following example records the current line and row numbers, moves the
cursor to the bottom of the screen, and prints a message; it then restores the
cursor to its original position and prints a message.
Example:
Example:
The following statements generate the five sets of results by means of the
LOG function.
8-76 Reference
10 FOR I = 1 TO 2 STEP .2
20 PRINT "LOG OF ";1 "= ";LOG(I)
30 NEXT I
40 END
LOG OF 1 = 0
LOG OF 1.2 = .1823216
LOG OF 1.4 = .3364723
LOG OF 1.6 = .4700037
LOG OF 1.8 = .5877868
LPOS LPOS(X)
Returns the current position of the line printer's print head within the line
printer buffer.
Example:
LPRINT and LPRINT USING are the same as PRINT and PRINT USING
except that output goes to the line printer instead of to the screen.
Example:
Reference 8-77
LSET LSET string-variable=string-expression
Moves data from memory to a random file buffer in preparation for a PUT
statement.
Note
LSET and RSET may also be used with a nonfielded string variable to
left-justify or right-justify a string in a given field.
The statements create custom Menu Bar options and items underneath
them, or restore the default Menu Bar.
The functions return the number of the last Menu Bar or menu item
selection made.
The menu-id is the number assigned to the Menu Bar selection. It can be a
value from 1 to 10.
The item-id -is the number assigned to the menu item underneath the Menu
Bar. It can be a value from 0 to 19. If item-id is between 1 and 19, it
specifies an item in the menu. If item-id is O. it specifies the entire menu.
For the state argument, use 0 to disable the menu or menu item, 1 to enable
it, or 2 to enable the item and place a check mark by it. If the item-id is 0,
8-78 Reference
the state takes effect for the entire menu. When you compose a menu item
which is to be checkmarked, you must leave two blank spaces ahead of the
item for the checkmark to be rendered.
The MENU RESET statement restores Amiga Basic's default Menu Bar.
This set of MENU statements and functions gives you the tools to build
custom menus and menu items in the Menu Bar at the top of the screen. If
a MENU ON statement is executed, the user's selection of custom menu
items can be trapped with the ON MENU GOSUB statement.
You can override the existing Amiga Basic menu items with the MENU
statement.
Example:
Reference 8-79
The following are examples of MENU functions.
Menuld=MENU(O)
Menultem=MENU(l)
MENU ON MENU ON
MENU OFF MENU OFF
MENU STOP MENU STOP
Example:
8-80 Reference
The filespec must include the filename used when the file was saved. That
file must have been saved in ASCII format to be merged. You can put a file
in ASCII format by using the A option to the SAVE command. If it was not
saved in ASCII format, a "Bad file mode" error message is generated.
Example:
MERGE ISortRoutine"
The function returns a string of length m characters from X$, beginning with
the nth character.
The optional m refers to the number of characters from string-exp2 that are
used in the replacement. If m is omitted, all of string-exp2 is used. The
replacement of characters never exceeds the original length of strlng-expl.
In the function syntax. the values nand m must be in the range 1 to 32767.
If m is omitted or if there are fewer than m characters to the right of the nth
character, all rightmost characters. beginning with the nth character, are
returned.
In the function syntax, the values nand m must be in the range 1 to 32767.
If m is omitted or if there are fewer than m characters to the right of the n
character, all rightmost characters, beginning with the nth character. are
returned. If n is greater than the number of characters in X$ (that is.
LEN(X$». MID$ returns a null string.
Reference 8-81
Example:
The following statements locate a specific field within a string and then
replace it with a new string.
Puts numeric values into string variables for insertion into random file
buffers.
You must convert numeric variables to string variables before placing them
in a random file. Use MKI$, MKL$, MKD$, and MKS$ for this purpose.
Then move the variable to the random file buffer using either LSET or
RSET, and write the buffer to the file using PUT#.
8-82 Reference
Instead of converting the binary value to its string representation, like the
STR$ function, MK$ moves the binary value into a string of the proper
length. This greatly reduces the amount of storage required for storing
numbers in a file.
Example:
The following example illustrates the use of MKI$, MKS$, and MKD$ with
random files.
See also: CVI, CVS, CVL, CVD, LSET, RSET, Chapter 5, "Working with
Files and Devices."
MOUSE MOUSE(n)
The MOUSE function returns information about the left mouse button and
the location of the mouse's cursor within the active window. MOUSE does
not monitor the right button, which is used to control the menu (see the
MENU function for information on monitoring menu selections).
MOUSE performs seven functions; specify any value from 0 through 6 as the
n parameter to select the desired function. The functions are described in
the sections that follow.
Reference 8-83
MOUSE(O): Mouse Button Position
MOUSE(O) gives the status of the left mouse button. After executing
MOUSE(O), Amiga Basic retains the start and end positions of the mouse
until a subsequent MOUSE(O) is executed. Therefore, after detecting the
movement of the mouse through MOUSE(O). a program should then use
MOUSE(3). MOUSE(4), MOUSE(5), and MOUSE(6) to determine the
starting and ending positions.
Value
Returned Explanation
o The left MOUSE button is not currently down, and it has not gone
down since the last MOUSE(O) function call.
1 The left MOUSE button is not currently down, but the operator
clicked the left button once since the since the last call to MOUSE
(0). To determine the start and end points of the selection, use
MOUSE(3), MOUSE(4), MOUSE(5), and MOUSE(6).
2 The left MOUSE button is. not currently down, but the operator
clicked the left button twice since the last call to MOUSE (0). To
determine the start and end points of the selection, use
MOUSE(3), MOUSE(4), MOUSE(5), and MOUSE(6). (Similarly,
a value of 3 indicates the button was clicked three times.)
-1 The operator is holding down the left mouse button after clicking it
once. The return of this value usually signifies that the mouse is
moving.
-2 The operator is holding down the left mouse button after clicking it
twice. The return of this value usually signifies that the mouse is
moving. (Similarly, a value of -3 indicates the button was clicked
three times.)
8-84 Reference
MOUSE(l): Current X Coordinate
MOUSE(l) returns the horizontal (X) coordinate of the mouse cursor the
last time the MOUSE(O) function was invoked, regardless of whether the
left button is down.
MOUSE(2) returns the vertical (Y) coordinate of the mouse cursor the last
time the MOUSE(O) function was invoked, regardless of whether the left
button was down.
MOUSE(3) returns the horizontal (X) coordinate of the mouse cursor the
last time the left button was pressed before MOUSE(O) was called. Use
MOUSE(3) in combination with MOUSE(4) to determine the starting point
of a mouse lnovement.
MOUSE(4) returns the vertical (Y) coordinate of the mouse cursor the last
time the left button was pressed before MOUSE(O) was called.
If the left button was down the last time MOUSE(O) was called, MOUSE(5)
returns the horizontal (X) coordinate where the mouse cursor was when
MOUSE(O) was called. If the left button was up the last time MOUSE(O)
was called, MOUSE(5) returns the horizontal (X) coordinate where the
mouse cursor was when the left button was released. Use MOUSE(5) to
track the mouse as the operator moves it and to determine the coordinate
where movement stops.
Reference 8-85
MOUSE(6): Ending Y Coordinate
\
Mouse Example
The following routine checks the movement of the mouse. As the mouse
moves, the routine moves a graphic image in array P to the new X and Y
positions.
CheokMouse:
IF MOUSE(O)=O THEN CheokNouse
IF ABS(X-NOUSE(l» > 2 THEN MovePicture
IF ABS(Y-NOUSE(2» < 3 THEN CheckNouse
NovePicture:
PUT(X.Y),P
X=NOUSE(l): Y=MOUSE(2)
PUT(X.Y),P
OOTO CheckNouse
MOUSE ON MOUSE ON
MOUSE OFF MOUSE OFF
MOUSE STOP MOUSE STOP
8-86 Reference
NAME NAME "old-filename" AS "new-filename"
Both parameters are string expressions. The old-filename must exist and
the new-filename must not exist. Otherwise. an error results.
Example:
In this example, the file that was formerly named Accounts becomes
LEDGER.
NEW NEW
Deletes the program currently in memory and clears all variables and the
List window.
NEW closes all files and turns off tracing mode. When you execute NEW,
the windows retain their sizes and locations.
Reference 8-87
OBJECT.AX OBJECT. AX object-id, value
OBJECT.AY OBJECT. AY object-id, value
The value specifies the acceleration rate in number of pixels per second per
second.
Defines a rectangle and instructs Amiga Basic not to draw objects outside
this area.
The xl and x2 parameters define the left and right boundaries of the
rectangle on the x axis, and yl and y2 define the top and bottom boundaries
on the y axis. The default value of the CLIP rectangle is the border of the
current Output window.
Note: If you change the size of the window using the Sizing Gadget, the
boundaries you have defined using OBJECT. CLIP aren't automatically
updated. That is, if you enlarge the window, the object remains within the
current bounds defined with the last OBJECT. CLIP executed.
8-88 Reference
If object-id is not specified. all objects in the current Output window are
released.
By default. all objects collide with each other and the border. This
statement can be used to allow some objects to pass through each other
without causing a collision.
For more information on defining MeMask and HitMask. see the Using
HitMask and MeMask section of the .. Graphics Animation Routines"
chapter in the Amiga ROM Kernel Manual for details.
Example:
Reference 8-89
The object-id corresponds to the object-id in an OBJECT. SHAPE
statement; it identifies an object within the current Output window that
OBJECT.ON or OBJECT.OFF will respectively make visible or invisible.
Example:
Sets the bob's pianePICK and place-on-off masks. For details see the
Amiga ROM Kernel Manual.
Two objects assigned the same priority are drawn in random order.
8-90 Reference
The object-id corresponds to the object-id in an OBJECT. SHAPE
statement; it identifies the object to be drawn.
The value is a number from -32768 to 32767 indicating the priority; the
higher the value specified, the higher the priority. For example, an object
with a priority of 8 is displayed "in front of" objects with a priority of 0
through 7.
OBJECT. SHAPE
Even though object-id2 and object-idl share memory, you can specify
different attributes to each using other OBJECT statements. Amiga Basic
initializes the values assigned to OBJECT.X, OBJECT.Y, OBJECT.VX,
OBJECT.VY, OBJECT.AX, and OBJECT.AY to 0 for this purpose.
Reference 8-91
Example:
In the above example, the static attributes of the object (including the size,
shape, and color) are in the file ball earlier created by the user with the
Object Editor program (see Chapter 7).
The following gives an example of an Amiga Basic routine that starts up and
handles collisions of the objects defined in ball. Refer to the other sections
of this chapter for an explanation of the COLLISION statement and the
other OBJECT statements.
8-92 Reference
OBJECT. START OBJECT. START [object-id [,object-id ... ]]
OBJECT. STOP OBJECT. STOP [object-id [,object-id ... ]]
The OBJECT. STOP statement freezes the motion of one or more objects.
When two objects collide, Amiga Basic does an OBJECT. STOP on both
objects. When one object collides with the border, Amiga Basic does an
OBJECT. STOP on the object.
Example:
OBJECT.VX
OBJECT.VY
Reference 8-93
The object-id corresponds to the object-id in an OBJECT. SHAPE
statement; it identifies the object to which the velocity applies.
The value in the statement defines the velocity in number of pixels per
second. The function returns the same value.
Example:
OBJECT.VX 1,30
OBJECT.VY 1,30
OBJECT.X
OBJECT.Y
You can use the statement to establish an initial starting point for animation,
or to relocate the object in the Output window during execution; animation
then resumes at the new starting point.
8-94 Reference
The OBJECT.X and OBJECT.Y functions return, respectively, the current
X and Y coordinates of the upper left corner of the object's rectangle.
Example:
OBJECT.X 1.10
OBJECT.Y 1,50
See OBJECT. SHAPE for an example of the use of this statement with other
OBJECT statements.
OCT$ OCT$(X)
Returns a string that represents the octal value of the decimal argument. X
is rounded to an integer before OCTS (X) is evaluated.
Example:
The following shows an example of some of the results displayed when a user
interacts with this program.
Reference 8-95
ON BREAK ON BREAK GOSUB label
ON BREAK GOSUB 0
Tells Arniga Basic to call the specified routine when the user presses
CTRL-C or selects Stop from the Run menu.
The label is a label or a line number in the subroutine that receives control
when the user tries to stop the program.
Example:
Tells Amiga Basic to call the specified routine when the COLLISION
function returns a non-zero value (that is, when an object collides with the
border or another object).
The label is a label or a line number in the subroutine that receives control.
GOSUB 0 disables the COLLISION event. The ON COLLISION statement
has no effect until the event has been enabled by the COLLISION ON
statement.
8-96 Reference
ON ERROR GOTO ON ERROR GOTO line
Example:
Reference 8-97
In the ON ... GOSUB statement. each line named in the list must be the first
line of a subroutine.
If the value of the expression is zero. or greater than the number of items in
the list (but less than or equal to 255). Amiga Basic continues with the next
executable statement. if the value of the expression is negative or greater
than 255. an "illegal function call" error message is generated.
Example:
Tells Amiga Basic to call the specified routine whenever the MENU (0)
function would return a non-zero value (that is. whenever the user selects a
menu item).
8-98 Reference
ON MOUSE ON MOUSE GOSUB label
ON MOUSE GOSUB 0
Tells Amiga Basic to call the specified routine whenever the user presses the
left mouse button.
Tells Amiga Basic to call the specified routine whenever a given time interval
has elapsed.
The statement causes an event trap every n seconds. The label is a label or
line number of a subroutine to which control is passed when the time
interval n elapses; n must be greater than zero and less than 86400 (the
number of seconds in 24 hours). GOSUB 0 disables the TIMER event.
The ON TIMER statement has no effect until the event has been enabled by
the TIMER ON statement.
Reference 8-99
OPEN
Statement Syntax 2
OPEN filespec [FOR mode] AS [#] filenumber [LEN=file-buffer-size]
A file must be opened before any I/O operation can be performed on that
file. OPEN allocates a buffer for I/O to the disk file or device and
determines the mode of access that is used with the file.
The filespec is a string expression containing the name of the file. optionally
preceded by the name of a volume or device.
Syntax 1
For the first syntax. the mode is a string expression whose first character is
one of the following:
8-100 Reference
o Specifies sequential output mode.
I Specifies sequential input mode.
R Specifies random input/output mode.
A Specifies sequential append mode.
Syntax 2
For the second syntax, the mode is one of the following keywords:
If the mode is omitted in the second syntax, the default, random access
mode, is assumed.
Example:
This statement determines the minimum value that array subscripts may
have. If n is 1, then 1 is the lowest value possiblej if n is 0, then 0 is the
lowest value possible. The default base is O. Specifying an OPTION BASE
other than 1 or 0 will result in a syntax error.
The OPTION BASE statement must be executed before arrays are defined
or used.
Reference 8-101
Example:
OPTION BASE 1
The x and yare coordinates of any point within an area in the window
containing a border--for example, any point within a circle, ellipse, or
polygon.
When specified, STEP indicates that the x and y coordinates specify a pixel
location relative to the last location referenced. When omitted. the x and y
coordinates specify an absolute location.
8-102 Reference
Example:
Defines a "paint can" and the color it holds for reference by other Amiga
Basic statements.
Note: The Amiga system uses color-id 0, 1, 2 and 3; any color assigned to
these numbers through a PALETTE statement overrides the system
assignments. The Amiga system initially defines color identification numbers
0, 1, 2. and 3 as follows:
o blue
1 white
2 black
3 orange
The red, green, and blue parameters each contain a value from 0.00
through 1.00 indicating a decimal percentage of red, green, and blue.
Combined, these parameters define a color. The table below shows the
specifications you make for red, green, and blue to obtain the colors
indicated in the left-hand column.
Reference 8-103
Colors Red Green Blue
The color you specify may override previous color assignments made by the
Amiga system.
Example:
PALETTE l,RND,RND,RND
PALETTE 2.RND,RND,RND
COLOR 1,2
The are- pattern is the name of an integer array containing the pattern. The
array defines a 16-bit wide by N-bit high mask to be used for polygon fill. In
this mask, N is the number of elements in the integer array. N must be a
power of two.
8-104 Reference
The values you specify for line-pattern and area-pattern determine the
appearance of the pattern. For more information on how the values relate
to the pattern drawn, see the Patterns section in the "Graphics Support
Routines" chapter of the Amiga Rom Kernel Manual.
Example:
DIM AREA.PAT%(3)
AREA.PAT%(O) = &H5555
AREA.PAT%(l) = &HAAAA
AREA.PAT%(2) = &H5555
AREA.PAT%(3) = &HAAAA
PATTERN &HFFF,AREA.PAT%
The returned value is an integer in the range 0 to 255. The address must be
in the range 0 to 16777215.
See also the POKE statement, which writes a one-byte integer to a specified
memory location.
Reference 8-105
See also the POKEL statement, which writes a long-integer word to a
specified memory location.
°
The address is a numeric expression in the range from to 16777216; it
represents the address of the memory location. The numeric expression
must be an even number; otherwise Amiga Basic displays an error message.
The arguments x and yare the coordinates in the current Output window of
the pixel to be referenced. The function returns a number that corresponds
to the color-id in a PALETTE statement.
Coordinates (0,0) define the upper left-hand corner of the current Output
window.
Coordinate values outside of the current Output window return the value -1.
POKE POKE I, J
8-106 Reference
I and J are integer expressions. The expression I represents the address of
the memory location, and J is the data byte in the range 0 to 255. I must be
in the range 0 to 16777215.
See also the PEEK statement, which returns a one-byte integer from a
specified memory location.
Warning
Use POKE carefully. Altering system memory can corrupt the system. If
this happens, reboot the Amiga.
See also the PEEKL statement, which returns a long-integer word from a
specified memory location.
Warning
Use POKEL carefully. Altering system memory can corrupt the system. If
this happens, reboot the Amiga.
Reference 8-107
POKEW POKEW address, value
See also the PEEKW statement, which returns a short-integer word from a
specified memory location.
Warning
Use POKEW carefully. Altering system memory can corrupt the system. If
this happens, reboot the Amiga.
The line number returned by POS is based on the width and height of the
character "0" in the Output window's current font.
Example:
The following example records the current line and row numbers, moves the
cursor to the bottom of the screen, and prints a message; it then restores the
cursor to its original position and prints a message.
8-108 Reference
Y = CSRLIN ' GET CURRENT CURSOR LINE NUMBER (VERTICAL POSITION)
X = POS(O) , GET CURRENT CURSOR COLUMN NUMBER (HORIZONTAL POSITION)
LOCATE 20,1 ' PLACE CURSOR ON LINE 20, ROW 1 (BOTTOM OF SCREEN)
PRINT "THIS PRINTS AT LOCATION 20,1 (BOTTOM OF PAGE)"
LOCATE Y,X ' PLACE CURSOR IN ORIGINAL LOCATION
PRINT "THIS PRINTS AT ORIGINAL LOCATION OF CURSOR"
PRESET works exactly like PSET, except that if you omit color-id. the
specified point is set to the background color.
When specified, STEP indicates that the x and y coordinates specify a pixel
location relative to the last location referenced. When omitted. the x and y
coordinates specify an absolute location.
STEP (xoffset.yoffset)
For example. if the most recently referenced point is (10.10). then STEP
(10.0) would reference a point at an offset of 10 from x and 0 from y; that
is. (20,10).
Displays data to the screen in the current Output window. (See LPRINT for
information on printing data on a printer.)
Reference 8-109
If the expression-list is omitted. a blank line is printed. If the
expression-list is included. the values of the expressions are printed in the
Output window. The expressions in the list may be numeric or string
expressions. (String constants must be enclosed in quotation marks.)
Print Positions
Note: You can use a question mark in place of the word PRINT in a PRINT
statement; This can be a time-saving shorthand tool. especially when
entering long programs with many consecutive PRINT statements.
8-110 Reference
PRINT USING PRINT USING string-exp,'expression-list
String Fields
Reference 8-111
\ \ causes three characters to be printed. If
you specify more spaces than are in the
field, Amiga Basic left-justifies the field
and pads the extra spaces to the right. If
you specify fewer spaces than are in the
field, Amiga Basic ignores the extra
characters in the field.
Numeric Fields
Amiga Basic allows the following special characters to define the format of
numeric expressions, as summarized below.
These characters are described in detail in the sections that follow. Amiga
Basic treats any other character in the format string as literal output. For
example.
8-112 Reference
/I
The # character specifies the positions that must be filled with a number
when the expression is printed. If the number has fewer positions than the #
positions specify. Amiga Basic justifies the number to the right and precedes
it with spaces.
You can insert a decimal point within a # field; Amiga Basic prints the #
digits specified on both sides of the decimal point. Amiga Basic precedes
the decimal point with a zero if necessary.
0.78
10.20 5.30 0.23
+
A plus sign at the beginning or end of the format string causes the sign of the
number (Plus or minus) to be printed before or after the number.
A minus sign at the end of the format field causes negative numbers to be
printed with a trailing minus sign. The following examples show use of the
plus and minus signs:
-68.95+2.40-9.00
68.95-22.457.00-
Reference 8-113
**
A double asterisk at the beginning of the format string causes leading spaces
in the numeric field to be filled with asterisks. The second asterisIs also
specifies positions for two or more digits. The statement
*12.39*-0.90765.10
$$
A double dollar sign causes a dollar sign to be printed to the immediate left
of the formatted number. The $$ specifies two more digit positions, one of
which is the dollar sign. The exponential format cannot be used with $ $.
Negative numbers cannot be used unless the minus sign trails to the right.
The statement
$456.78 $9.30
**$
The double asterisk dollar sign ( ...... $) at the beginning of a format string
combines the effects of tne two symbols. Leading spaces are filled with
asterisks and a dollar sign is printed before the number. ... ... $ specifies three
more digit positions,one of which is the dollar sign.
Do not use the exponential format with ...... $. In negative numbers, minus
signs appear immediately to the left of the dollar sign. The example
***$2.34*$999.90
8-114 Reference
If you place a comma to the left of the decimal point in a format string,
Amiga Basic prints a comma to the left of every third digit. (This has no
effect on the portion of the number to the right of the decimal point.) If you
place a comma at the end of the format string, Amiga Basic prints it as part
of the string. A comma specifies another digit position; it has no effect if
specified with exponential CAAA) expressions. The example
1,234.50
1234.50,
!12.34!
112.347
Place four carets CAAA) after the digit position characters to specify
exponential format. The four carets allow space for E+ to be printed. You
can also specify a decimal point position. Amiga Basic justifies the
significant digits to the left, adjusting the exponent; unless you specify a
leading + or trailing + or -, Amiga Basic prints a space or minus sign to the
left of the decimal point. The following examples show the exponential
format:
Reference 8-115
PRINT USING "##.##""";234.56
PRINT USING ".####,"'";888888
PRINT USING "+.##"''''';123
2.S5E+02
. 8889E+06
+.12E+OS
% Overflow Indicator
If a number is too large to fit within a field. Amiga Basic prints a % character
in the result to indicate an overflow. as shown in the next example.
%987.65
If the number of digits specified exceeds 24. Amiga Basic issues the "Illegal
function call" message.
PRINT#
PRINT# USING PRINTH /ilenumber, [USING string-exp; 1 expression-list
The /ilenumber corresponds to the number specified when the file was
opened for output. The string-exp can consist of any of the formatting
characters described under "PRINT USING." The expression-list items are
numeric or string expressions to be written to the file.
PRINT# does not compress data. but rather writes it to the file just as PRINT
displays it on a screen. Therefore. be sure to delimit the data to ensure
writing only the data you require in the correct format.
8-116 Reference
Delimit numeric expressions in expression-list as shown in the following
example:
PRINT N1,A;B;C;X;Y;Z
A$ := "CAMERA"
B$ = "93604 - 1"
PRINTN l,A$;B$
CAMERA93604-1
PRINTN 1.A$;",";B$
CAMERA,93604-1
Reference 8-117
A$ = "CAMERA, AUTOMATIC"
B$ = "93604-1"
PRINT #l,A$;B$
CAMERA, AUTOMATIC93604-1
INPUT #l,A$.B$
A$ "CAMERA"
B$ "AUTOMATIC93604-1"
To write the data correctly to the file. use eRR$ (34) to specify double
quotation marks as follows:
A$ "CAMERA, AUTOMATIC"
B$ "93604-1"
You can also use the PRINT# statement with the USING option to control
the format of the file, as shown below.
PRINT#l,USING"$$###.##,";J;K;L
8-118 Reference
PSET PSET [STEP] (X,y) [,co[or-id ]
When specified, STEP indicates that the x and y coordinates specify a pixel
location relative to the last location referenced. When omitted, the x and y
coordinates specify an absolute location.
Example:
PTAB PTAB(X)
PTAB is similar to TAB, except that PTAB indicates the pixel position
rather than the character position to advance to. If the current print
position is already beyond pixel X, PTAB retreats to that pixel on the same
line. Pixel 0 is the leftmost position. I must be in the range Oto 32767.
PTAB may only be used in PRINT statements.
Reference 8-119
PUT PUT [I] filenumber [,record-number]
PUT [STEP] (x,y),array [(index [,index ... ])] [.action-verb]
The two syntaxes shown above correspond to two different uses of the PUT
statement. These are called a random file PUT and a screen PUT.
respectively.
For the first syntax, the filenumber is the number under which the file was
opened. If the record-number is omitted. Amiga Basic will assume the next
record number (after the last PUT). The largest possible record number is
1677 7215; the smallest is 1.
In the case of WRITE#. Amiga Basic pads the buffer with spaces up to the
carriage return. Any attempt to read or write past the end of the buffer
causes a .. Field overflow" error message to be generated.
Screen PUT
In the second syntax. PUT uses(xl, yl) as the pair of coordinates specifying
the upper left-hand corner of the rectangular image to be placed on the
screen in the current Output window.
The array is the name assigned to the array that holds the image. (See
"GET" for a discussion of array name issues.)
The index allows you to PUT multiple objects in each array. This technique
can be used to loop rapidly through different views of an object in
succession.
8-120 Reference
The action-verb is one of the following: PSET, PRESET, AND, OR, XOR.
The action-verb performs the interaction between the stored image and the
one already on the screen.
Example:
PUT (O,O),BobArray,PSET
See also: GET, PRESET, PSET, PRINT, WRITE. FIELD, LSET. RSET
This statement reseeds the random number generator with the expression, if
given, where the expression is either an integer between -32768 and 32767,
inclusive, or where the expression is TIMER. If the expression is omitted,
Amiga Basic suspends program execution and asks for a value before
randomizing, by printing:
If the random number generator is not reseeded, the RND function returns
the same sequence of random numbers each time the program is run. To
change the sequence of random numbers every time the program is run,
place a RANDOMIZE statement at the beginning of the program and
change the argument with each run.
Reference 8-121
READ READ variable-list
A single READ statement may access one or more DATA statements (they
are accessed in order), or several READ statements may access the same
DATA statement. If the number of variables in the variable-list exceeds
the number of elements in the DATA statements, Amiga Basic issues an
"Out of data" error message. If the number of variables specified is fewer
than the number of elements in the DATA statements, later READ
statements begin reading data at the first unread element. If there are no
subsequent READ statements, the extra data is ignored.
To reread DATA statements from the start, use the RESTORE statement.
DIM CF(19)
FOR 1=1 TO 19
READ CF(I)
PRINT CF(I)
NEXT I
DATA 0,2,4,5,7,9,11,0,1,-1, 0,0,0,0,0,0, -12,12,0
REM statements are not executed but appear exactly as entered when the
program is listed.
8-122 Reference
Note: You can use an apostrophe (') in place of the word REM in a
comment. This can be a time-saving shorthand tool, especially when
entering long programs with many consecutive REMark statements.
Warning: The DATA statement treats REM as valid data, so don't specify
it in a DATA statement unless you want it considered as data.
MainLoop:
SOUND RESUME
RESTORE Song
OOSUB PlaySong
OOTO MainLoop
Song:
DATA 1,3,3,3
DATA 12g>ge, 12p2de, 12p216gaf#g3a, 16p6gab>dcced
RESUME RESUME
RESUME 0
RESUME NEXT
RESUME line
Anyone of the four syntaxes shown above may be used, depending upon
where execution is to resume:
Reference 8-123
RESUME or RESUME 0 Execution resumes at the
statement that caused the error.
The line in the RETURN statement acts as with a GOTO. If no line is given,
execution begins with the statement immediately following the last executed
GOSUB statement.
Amiga Basic includes the RETURN line enhancement that lets processing
resume at a line that has a number or label. Normally, the program returns
to the statement immediately following the GOSUB statement when the
RETURN statement is encountered. However. RETURN line enables the
user to specify another line. This permits you more flexibility in program
design. This versatile feature. however. can cause problems for untidy
programmers. Assume. for example. that your program contains these
fragments of a program:
8-124 Reference
15 MOUSE ON
10 ON MOUSE GOSUB 1000
20 FOR I = 1 TO 10
SO PRINT I
40 NEXT I
50 REM NEXT PROGRAM LINE
If mouse activity takes place while the FOR ... NEXT loop is executing. the
subroutine is performed. but program control returns to line 200 instead of
completing the FOR... NEXT loop. The original GOSUB entry is canceled
by the RETURN statement, and any other GOSUB, WHILE, or FOR that
was active at the time of the trap remains active. Using a RETURN from
within a FOR loop is not good programming practice and should be
discouraged.
RIGHTS RIGHT$(X$,l)
Reference 8-125
Example:
The following routines show the use of RIGHT$ in extracting a field from
within a string containing several fields.
RND RND[(X)]
RND issues the same sequence of random numbers each time a program is
run unless you specify a RANDOMIZE statement.
Example:
8-126 Reference
FOR I =1 TO 40
X = INT(RND*620) 'SET HORIZONTAL LOCATION OF CENTER
Y =
INT(RND*200) 'SET VERTICAL LOCATION OF ENTER
RADIUS =
40*RND 'SET A RANDOM RADIUS
CIRCLE (X,Y) ,RADIUS 'DRAW A CIRCLE
NEXT I
Moves data from memory to a random file buffer in preparation for a PUT
statement.
With the second form of the syntax, the named file is loaded from disk into
memory and run. If there is a program in memory when the command
executes. a requester appears permitting the program to be saved.
In the second syntax. the filename must be that used when the file was
saved.
RUN closes all open files and deletes the current contents of memory before
loading the designated program. However, with the R option, all data files
remain open.
Reference 8-127
SADD SADD (string expression)
Returns the address of the first byte of data in the specified string
expression.
This value is only dependable until another string allocation occurs because
subsequent string allocations may cause existing strings to move in memory.
SADD is typically used to pass the address of a string to a machine language
program.
Avoid using VARPTR (string$ ) since the format of string descriptors may
change in the future.
Example:
The A option saves the file in ASCII format. If the A option is not
specified, Amiga Basic saves the file in a compressed binary format that can
also be specified with the B option. ASCII format takes more space on the
disk, but some programs require that files be in ASCII format. For instance,
the MERGE command requires an ASCII format file. Application programs
may also require ASCII format in order to read the file.
8-128 Reference
The P option protects the file by saving it in an encoded binary format.
When a protected file is later RUN (or loaded with LOAD). any attempt to
list or edit it will fail.
Once a file is MERGEd. its format is in ASCII. To save the file in
compressed format, use the SAVE command with no option or with option
B.
The filename can include a drive number or library name. For example. to
save file "test" to drive 1, enter:
SAVE "dfl:test"
To save the same file to a library named "datafils." enter:
SAVE "datafils/test"
For further information on file specification. see Chapter 5.
Translates a list of codes you specify into a voice delivering audible speech
of any language.
The string contains a list of phoneme codes. (Phonemes are units of speech
composed of the syllables and words of a spoken language.) The
mode-array, if present. is an integer array of at least 9 elements. The
specifications you make in the elements define the characteristics of the
voice that is speaking. If mode-array, is not an integer. a type mismatch
error occurs.
The following table gives the values you can specify in mode-array to
describe the characteristics of the voice that is to speak. If you don't specify
mode-array (it is optional). the default values indicated in the table are in
effect.
Reference 8-129
Argument Element # Description
1 Monotone (robot-like).
1 Female voice
8-130 Reference
Argument Element # Description
Reference 8-131
Channel Assignment Codes
Value Channel(s)
o o
1 1
2 2
3 3
4 o and 1
5 o and 2
6 3 and 1
7 3 and 2
8 either available left channel
9 either available right channel
10 either available left/right pair of channels (the default)
11 any available single channel
Example:
SCREEN
SCREEN CLOSE SCREEN screen-id , width, height, depth, mode
SCREEN CLOSE screen-id
In creating the screen, SCREEN allocates private memory for a bit map.
8-132 Reference
The SCREEN CLOSE statement releases memory allocated to the screen
identified by screen-fd.
The width is the width of the screen in pixels. Specify a value from 1
through 640.
The height is the height of the screen in pixels. Specify a value from 1
through 400.
The depth is the number of bit planes associated with the screen. The value
you specify (1, 2. 3, 4, or 5) determines the number of colors that can be
displayed on the screen, as shown in the following table.
Value Number of
Colors
1 2
2 4
3 8
4 16
5 32
The mode determines the pixel width of the screen (320 pixels per
horizontal line for low resolution and 640 pixels for high resolution) and
whether the screen is to be interlaced. Normally, you specify low resolution
for home television screens, and high resolution for high-resolution
monochrome and RGB monitors.
Reference 8-133
The table below shows the values you can specify for mode, and the resulting
screen produced.
Example:
SCREEN 1,320,200,5,1
WINDOW 2, "Lines", (10,10)-(270,170),15,1
The rectangle has the form (xl,yl)-(x2,y2), which specifies the bounds of
the rectangle in the current Output window that is scrolled.
The delta-x parameter indicates the number of pixels to scroll right. If the
parameter is a negative number, the rectangle scrolls left.
The delta-y parameter indicates the number of pixels the rectangle will
scroll down. A negative value will scroll the rectangle up.
8-134 Reference
SGN SGN(X)
Example:
In the following example, SON evaluates a negative, zero, and positive value
respectively.
PRINT SGN(-299)
PRINT SGN (499 - 499)
PRINT SGN (8722)
-1
o
1
Reference 8-135
The SHARED statement can only be used within a subprogram. A
subprogram can have several SHARED statements for different variables.
just like a program can have several DIM statements for different variables.
SIN SIN(X)
Example:
SINE OF 1 IS .841471
SINE OF 100 IS -.5063657
SINE OF 1000 IS .8268796
SLEEP SLEEP
8-136 Reference
Example:
LOOP:
1$ = INKEY$
IF I$ = ~X" THEN STOP
SLEEP
ooTO LOOP
Produces a sound from the speaker, bui~ds a queue of sounds, and plays a
queue of sounds.
The following table shows four octaves of notes and their corresponding
frequencies. Note that doubling the frequency produces a note one octave
higher.
C 130.81 C* 523.25
D 146.83 D 587.33
E 164.81 E 659.26
F 174.61 F 701.00
Reference 8-137
Note Frequency Note Frequency
G 196.00 G 783.99
A 220.00 A 880.00
B 246.94 B 993.00
C 261.63 C 1046.50
D 293.66 D 1174.70
E 329.63 E 1318.50
F 349.23 F 1396.90
G 392.00 G 1568.00
A 440.00 A 1760.00
B 493.88 B 1975.50
*Middle C
slow Adagietto
Andante 76-108 14.8-10.42
8-138 Reference
Tempo Beats Per Minute Duration
medium Andantino
Moderato 108-120 10.42-9.38
fast Allegretto
Allegro 120-168 9.38-6.7
Vivace
Veloce
Presto
The volume can range from 0 (lowest volume) to 255 (highest volume). The
default volume is 127.
The voice indicates which of four Amiga audio channels the sound will come
from. Specify 0 or 3 for the audio channel to the left speaker and lor 2 for
the right speaker. The default is O.
Example:
SOUND 440,20,100,0
Reference 8-139
Example:
INDENT5$ = SPACE$(5)
INDENT10$ = SPACE$(lO)
PRINT "Level 1 Outline Heading"
PRINT INDENT5$ "Level 2 Heading"
PRINT INDENT5$ "Level 2 Heading"
PRINT INDENT10$ "Level 3 Heading
PRINT INDENT10$ "Level 3 Heading"
PRINT "Level 1 Heading"
END
SPC spe(X')
SPC can be used only with PRINT and LPRINT statements. X must be in
the range 0 to 255. A semicolon (;) is assumed to follow the SPC(X)
function.
8-140 Reference
Example:
FOR I = 1 TO 5
PRINT SPC(I) "I AM 1 COLUMN TO THE RIGHT OF THE ABOVE LINE"
NEXT I
SQR SQR(X)
X must be >= O.
Example:
Reference 8-141
The following is displayed on the screen:
1 1
2 1.414214
3 1.732051
4 2
5 2.236068
6 2.44949
7 2.645751
8 2.828427
9 3
10 3.162278
STICK STICK(n)
o Joystick A in X direction
1 Joystick A in Y direction
2 Joystick B in X direction
3 Joystick B in Y direction
Value Meaning
8-142 Reference
STOP STOP
STRIG STRIG(n)
This function returns the information shown in the table below depending on
what you specify for n.
Reference 8-143
STR$ STR$(X)
The string returned includes a leading space for positive numbers and a
leading minus sign for negative numbers.
STR$ is not used to convert numbers into strings for random file operations.
For that purpose, use the MKI$, MKS$, and MKD$ functions.
The first syntax returns a string of length I whose characters all have ASCII
code J.
The second syntax returns a string of length I whose characters are all the
first character of X$.
Example:
cccccccccc
##########
~
8-144 Reference
SUB SUB subprogram-name [(Jormal-parameter-list)] STATIC
END SUB END SUB
EXIT SUB EXIT SUB
STATIC means that all the variables within the subprogram retain their
values from the time control leaves the subprogram until it returns.
The body of the subprogram, the statements that make it up, occurs between
the SUB and END SUB statements.
The END SUB statement marks the end of a subprogram. When the
program executes END SUB. control returns to the statement following the
statement that called the subprogram.
The EXIT SUB statement routes control out of the subprogram and back to
the statement following the CALL subprogram statement.
Reference 8-145
Before Amiga Basic starts executing a program, it checks all
subprogram-related statements. If any errors are found, the program
doesn't execute. The mistakes are not trappable with ON ERROR. nor do
they have error codes. The following messages can appear in an error
requester when the corresponding mistake is made:
Example:
8-146 Reference
SWAP SWAP variable. variable
Example:
FRED JONES
JONES FRED
SYSTEM SYSTEM
The same result can be achieved by selecting the Quit item from the Project
menu.
Reference 8-147
TAB TAB (X)
If the current print position is already beyond space X, TAB goes to that
position on the next line. Space 1 is the leftmost position, and the rightmost
position is the width minus one. X must be in the range 1 to 155. TAB may
only be used in PRINT and LPRINT statements. A semicolon (;) is
assumed to precede and to follow the TAB(X) function.
Example:
8-148 Reference
Example:
TIME$ TIMES
Example:
The following example shows the use of TIMES in displaying the time of
day.
08:00:40
Reference 8-149
TIMER ON TIMER ON
TIMER OFF TIMER OFF
TIMER STOP TIMER STOP
TIMER
The statements enable, disable, and suspend event trapping based on time.
The function retrieves the number of seconds that have elapsed since
midnight.
The TIMER function can be used to generate a random number for the
RANDOMIZE statement. It can also be used to time programs or parts of
programs.
Example:
8-150 Reference
The string contains the words that are to be translated and. after execution.
the variable contains the phoneme string. The result returned to variable
cannot exceed 32767 characters.
Example:
TRON TRON
TROFF TROFF
The Trace On option in the Run menu is the same as the TRON statement.
If there is more than one statement on a line, each statement is run and
highlighted separately. The trace flag is disabled with the TROPP statement,
the Trace Off menu option, or when a NEW command is executed.
Reference 8-151
UCASE$ UCASE$ (string-expression)
The UCASE$ function provides you with a way to compare and sort strings
that have been entered with different uppercase and lowercase formats. For
example. if you had a program line.
the user might enter. "YES", "Yes", "yes". "Y". or "y". You could route
program control in the next statement by testing the first letter of the
UCASE$ of the ANSWER$ against "y". This. makes different affirmative
responses of different users work in the program. Another use of the
UCASE$ function is when you have a form entry program.
The person or people putting in form data may not consistently use
uppercase format. For example. a user might enter the names "atlanta".
"AUSTIN", and "Buffalo". If a normal Amiga Basic program to
alphabetize names sorted these three. they would be ordered" AUSTIN".
"Buffalo". and finally. "atlanta". because when strings are sorted they are
compared based on their ASCII character numbers. The ASCII character
number for "A" is lower than that for "B". but all uppercase letters come
before the lowercase letters, so the character "B" comes before the
character "a". If you sort based on the UCASE$ representation of the
strings. the results are alphabetically ordered.
Example:
a$=UCASE$(a$)
IF a$="Y" THEN Response:1
IF a$="N" THEN Response=2
IF a$="C" THEN Response=3
8-152 Reference
Here is another example:
A$ = "AUSTIN"
B$ :: "atlanta"
C$ = ·WaXAhachIE"
PRINT A$.B$.C$
PRINT UCASE$(A$).UCASE$(B$).UCASE$(C$)
Notice the difference in output, shown below, between the two PRINT
statements:
Returns the numeric value of string XS. The VAL function also strips
leading blanks. tabs. and Iinefeeds from the argument string.
VAL is not used to convert random file strings into numbers. For that
purpose, use the CVI, CVL. CVS, and CVD functions.
VARPI'R VARPTR(variable-name)
Returns the address of the first byte of data identified with the
variable-name. A value must be assigned to the variable-name before
execution of VARPTR. Otherwise. Amiga Basic issues an "Illegal function
call" error message. Any type variable name may be used (numeric. string.
array) . For string variables. the address of the first byte of the string
descriptor is returned. The address returned is a number in the range 0 to
16777215. For further information, see Appendix D. "Internal
Representation of Numbers."
Reference 8-153
Use VARPTR to obtain the address of a variable or array to be passed to an
assembly language subroutine. A function call of the form VARPTR(A(O)
is usually specified when passing an array. so that the lowest-addressed
element of the array is returned.
Note
All simple variables should be assigned before calling V ARPTR for an array
element. because the addresses of the arrays change whenever a new simple
variable is assigned.
Example:
8-154 Reference
height number in each element of the array. The height numbers, when put
together, define a curve; that curve is the shape of the wave.
The voice indicates from which of four Amiga audio channels the sound will
come from. Specify 0 or 3 for the audio channel to the left speaker and 1 or
2 for the right speaker.
The wave-definition defines the shape sound wave for voice. The
wave-definition can be SIN or the name of an array of integers with at least
256 elements. Each element in the array must be in the range of -128 to
127.
To save space, use the ERASE statement to delete the wave-definition array
after the WAVE statement is executed.
Example:
DEFINT A-Z
DIU Timbre(255)
FOR 1",0 TO 255
READ Timbre(I)
NEXT I
WAVE O,SIN
WAVE 1, Timbre
WAVE 2,Timbre
WAVE a,Timbre
Reference 8-155
WHILE ... WEND loops may be nested to any level. Each WEND matches
the most recent previous WHILE that has not been completed with an
intervening WEND. An unmatched WHILE statement causes a "WHILE
without WEND" error message to be generated, and an unmatched WEND
statement causes a "WEND without WHILE" error message to be
generated.
Warning
Do not direct program flow into a WHILE ... WEND loop without entering
through the WHILE statement, as this will confuse Amiga Basic's program
flow control.
Example:
The statement sets the printed line width and print zone width in the number
of standard characters for any output device.
8-156 Reference
The integer size is the number of standard characters that the named output
device line may contain. However, the position of the pointer or the print
head, as given by the POS or LPOS function, returns to zero after position
255. In Amiga's proportionally spaced fonts, the standard width for screen
characters is the equivalent of the width of any of the numerals 0 through 9.
The default line width for the screen is 255.
If the size is 255, the line width is "infinite"; that is, Amiga Basic never
inserts a carriage return character.
The filenumber is a numeric expression that is the number of the file that is
to have a new width assignment.
If the device is specified as "SCRN:", the line width is set at the screen.
Because of proportionally spaced fonts, lines with the same number of
characters may not have the same length.
If the output device is specified "LPT1:", the line width is set for the line
printer. The WIDTH LPRINT syntax is an alternative way to set the printer
width.
When files are first opened, they take the device width as their default
width. The width of opened files may be altered by using the second
WIDTH statement syntax shown above.
Reference 8-157
WINDOW WINDOW window-id [, [title] [, [rectangle] [. [type] [,screen-id]]]]
WINDOW CLOSE window-id
WINDOW OUTPUT window-id
WINDOW(n)
• Makes the window current. That is, you can use statements
such as PRINT, CIRCLE, and PSET to write text and graphics
to the window.
The title is a string expression that is displayed in the window's Title Bar, if it
has a Title Bar. Window 1 displays the name of the current program or
"BASIC" if no program is loaded when Amiga Basic initializes it.
8-158 Reference
The following table shows the values you can use in determining type.
Value Meaning
1 Window size can be changed using the mouse and Sizing Gadget
in the lower right-hand side of the window.
8 Window can be closed using the mouse and Close Gadget in the
upper left-hand comer of the window.
Indicate type by adding two or more of the values in the above table; for
example, specify 5 to indicate that the user can move the window by the
Title Bar and change its size through the Sizing Gadget in the lower
right-hand comer of the window. Any number from 0 through 31 is a valid
type specification.
Note: If you specify Type 1 and Type 16 (for a total of 17) Amiga Basic
reserves enough memory for the window to grow to the full size of the
screen. Otherwise, Amiga Basic reserves only enough memory for the
window size you specify; this specification consumes a large amount of
memory. If the memory available to your program is limited, avoid
specifying this combination in the type specification.
Reference 8-159
The rectangle specifies the physical screen boundary coordinates of the
created window. It has the form (x1,y1)-(x2,y2) where (x1,y1) is the
upper-left coordinate and (x2,y2) the lower-right coordinate (relative to the
screen). If no coordinates are specified, the window appears at the current
default for that window (the window-id's current values). The initial
defaults are for a full screen.
8-160 Reference
it Argument Information returned
Example:
WINDOW l,"Lines",(10.10)-(270,70).15
WINDOW 2. "polygons". (310.10)-(580.70).15
WINDOW 3, "Circles". (10.95)-(270.170),15
WINDOW OUTPUT 1
Reference 8-161
WRITE WRITE [expression-list]
When the printed items are output, each item is separated from the last by a
comma. Printed strings are delimited by quotation marks. After the last
item in the list is printed, Amiga Basic inserts a carriage return/linefeed
sequence.
WRITE outputs numeric values without the leading spaces PRINT puts on
positive numbers.
Example:
A • 80 : B 90 C$ = "The End"
WRITE A,B,C$
PRINT A,B,C$
END
Note the difference between the WRITE and PRINT output, shown below.
The filenumber is the number under which the file was opened with the
OPEN statement. The expressions in expression-list are string or numeric
expressions. They must be separated by commas.
8-162 Reference
The difference between WRITE# and PRINT# is that WRITE# inserts
commas between the items as they are written to the file and delimits strings
with quotation marks. Therefore, it is not necessary to put explicit
delimiters in the list. A carriage return/linefeed sequence is inserted after
the last item in expression-list is written to the file.
Example:
32 -6 Kathleen
Reference 8-163
Appendices
Appendices A-1
Dec Hex CHR Dec Hex CHR Dec Hex CH
A-2 Appendices
Non-ASCII Character Codes
i
177
178
B1
B2
-
~
207
208
CF
DO
CIt
Appendices A-3
Appendix B: Error Codes and Error Messages
Operational Errors
Error
Code Message
2 SYNTAX ERROR
A line is encountered that contains some incorrect sequence of
characters (such as an unmatched parenthesis, a misspelled
command or statement, or incorrect punctuation).
4 OUT OF DATA
A READ statement is executed when there are no DATA
statements with unread data remaining in the program.
A-4 Appendices
6 OVERFLOW
The result of a calculation is too large to be represented in
Amiga Basic's number format. If underflow occurs, the result is
zero and execution continues without an error.
7 OUT OF MEMORY
A program is too large, has too many FOR loops or GOSUBs, too
many variables, or expressions that are too complicated.
8 UNDEFINED LABEL
A line referenced in a GOTO, GOSUB, IF ... THEN[ ... ELSE], or
DELETE statement does not exist.
10 DUPLICATE DEFINITION
Caused by one of three conditions:
Appendices A-5
11 DIVISION BY ZERO
Caused by one of two conditions:
12 ILLEGAL DIRECT
A statement that, is illegal in immediate mode is entered as an
immediate mode command. For example, DEF FN.
13 TYPE MISMATCH
A string variable name is assigned a numeric value or vice versa; a
function that expects a numeric argument is given a string
argument or vice versa. This error can also be caused by trying to
SWAP single precision and double precision values.
A-6 Appendices
17 CAN'T CONTINUE
An attempt is made to continue a program that:
19 NO RESUME
An error-handling routine is entered, but it contains no RESUME
statement.
21 UNPRINTABLE ERROR
An error message is not available for the error condition which
exists. This is usually caused by an ERROR statement with an
undefined error code.
22 MISSING OPERAND
An expression contains an operator without a following operand.
Appendices A-7
26 FOR WITHOUT NEXT
A FOR statement is encountered without a matching NEXT
statement.
35 UNDEFINED SUBPROGRAM
A subprogram is called that is not in the program.
38 UNDEFINED ARRAY
An array was referenced in a SHARED statement before it was
created.
39, 40, 41, 42, 43. 44, 45, 46, 47. 48. and 49 UNPRINTABLE ERROR
A-8 Appendices
Disk Errors
Error
Code Message
50 FIELD OVERFLOW
A FIELD statement is attempting to allocate more bytes than
were specified for the record length of a random access file.
51 INTERNAL ERROR
An internal malfunction has occurred in Amiga Basic. Report to
Commodore-Amiga the conditions under which the message
appeared.
Appendices A-9
55 FILE ALREADY OPEN
A sequential output mode OPEN is issued for a file that is
already open or a KILL is given for a file that is open.
61 DISK FULL
All disk storage space is in use.
A-10 Appendices
68 DEVICE UNAVAILABLE
The device that has been specified is not available at this time.
73 ADVANCED FEATURE
74 UNKNOWN VOLUME
A reference was made to a volume which has not been mounted.
Appendices A-11
Errors Reported Before Program Execution Begins
Syntax Error
A line is encountered that contains some incorrect sequence of
characters (such as an unmatched parenthesis, a misspelled
command or statement, or incorrect punctuation).
IF without END IF
ELSE/ ELSE IF /END IF without IF
BLOCK ELSE/END IF must be the first statement on the line
FOR without NEXT
NEXT without FOR
WHILE without WEND
WEND without WHILE
Tried to declare SUB within a SUB
SUB already defined
Missing STATIC in SUB statement
EXIT SUB outside of a subprogram
SUB without END SUB
SHARED outside of a subprogram
Statement illegal within subprogram
Too many subprograms
A-12 Appendices
Appendix C: Amiga Basic Resenred Words
The following is a list of reserved words used in Amiga Basic. If you use
these words as variable names, a syntax error will be generated.
Appendices A-13
OBJECT.ON PUT SWAP
OBJECT. PLANES SYSTEM
OBJECT .PRIORITY RANDOMIZE TAB
OBJECT. SHAPE READ TAN
OBJECT. START REM THEN
OBJECT. STOP RESTORE TIME$
OBJECT.VX RESUME TIMER
OBJECT.VY RETURN TO
OBJECT.X RIGHT$ TRANSLATE $
OBJECT.Y RND TROFF
OCT$ RSET TRON
OFF RUN
ON SADD UBOUND
OPEN SAVE UCASE$
OPTION SAY USING
OR SCREEN
OUTPUT SCROLL VAL
SGN VARPTR
PAINT SHARED
PALETTE SIN WAIT
PATTERN SLEEP WAVE
PEEK SOUND WEND
PEEKL S PACE $ WHILE
PEEKW SPC WIDTH
POINT SQR WINDOW
POKE STATIC WRITE
POKEL STEP
POKEW STICK XOR
POS STOP
PRESET STR$
PRINT STRIG
PSET STRING$
PTAB SUB
A-14 Appendices
Appendix D: Internal Representation
of Numbers
Amiga Basic uses binary math. In the tables that follow, internal
representation is expressed in hexadecimal numbers.
External Internal
Representation Representation
-32768 8000
-1 FFFF
0 0000
1 0001
32767 7FFF
Binary Math
With the binary math pack, the default type for variables is single precision,
and built-in mathematical functions perform in single precision or double
precision. Single precision is much faster but less precise than double
precision.
Double Precision
Eight bytes as follows: One bit sign followed by 11 bits of biased exponent
followed by 53 bits of mantissa (including the implied leading bit which has a
value of 1). If the sign bit is 0, the number is positive. If the sign bit is 1,
the number is negative. The unbiased exponent (biased exponent -3FF hex
or -1023 decimal) is the power of 2 by which the mantissa is to be
Appendices A-iS
multiplied. The mantissa represents a number greater than or equal to 1
and less than two. Positive numbers may be represented up to but not
including 1.79 * 10 A308. The smallest representable number is 2.23 * 10
A-308. Binary double precision numbers are represented with up to 15.9
digits of precision.
External Internal
Representation Representation
1 3FFOOOOOOOOOOOOO
-1 BFFOOOOOOOOOOOOO
o 000xxxxxxx:xxxxxx
10 4024000000000000
0.1 3FB9999999999999
Single Precision
Four bytes as follows: One bit sign followed by 8 bits of biased exponent
followed by 24 bits of mantissa (including the implied leading bit which has a
value of 1). If the sign bit is 0, the number is positive. If the sign bit is 1, the
number is negative. The unbiased exponent (biased exponent -7F hex,
-127 decimal) is the power of 2 by which the mantissa is to be multiplied.
The mantissa represents a number greater than or equal to 1 and less than 2.
Positive numbers may be represented up to but not including 3.4 * 10 A38.
The smallest representable number is 1.18 * lOA -38. Binary single
precision numbers are represented with up to 7.2 digits of precision.
External Internal
Representation Representation
1 3F800000
-1 BF800000
o OOyxxxxx
10 41200000
0.1 3DCCCCCD
A-16 Appendices
Appendix E: Mathematical FUllctions
The derived functions that are not intrinsic to Amiga Basic can be calculated
as follows.
Mathematical Amiga
Function Basic Equivalent
COSECANT CSC(X)=lISIN(X)
COTANGENT COT(X)=llTAN(X)
INVERSE ARCSEC(X)=ATN(X/SQR(X*X-l»
SECANT +SGN(SGN(X)-l) * 1.5708
INVERSE ARCCSC(X)=ATN(X/SQR(X*X-1»
COSECANT +(SGN(X)-l) *1.5708
Appendices A-17
Mathematical Amiga
Function Basic Equivalent
HYPERBOLIC COTH(X)=EXP(-X)/(EXP(X)
COTANGENT -EXP(-X» *2+1
INVERSE ARCSINH(X)=LOG(X+SQR(X·X+1»
HYPERBOLIC SINE
INVERSE ARCCOSH(X)=LOG(X+SQR(X·X-i)
HYPERBOLIC COSINE
INVERSE ARCSECH(X)=LOG«SQR(-X*X+1)
+l)/X)
HYPERBOLIC SECANT
INVERSE ARCCSCH(X)
HYPERBOLIC COSECANT =LOG«SGN(X) *SQR(X·X+l)+l)/X
INVERSE ARCCOTH(X)=LOG«X+i)/(X-i»/2
HYPERBOLIC COTANGENT
A-18 Appendices
Appendix F: LIBRARY FORMAT
This appendix describes the mechanism that Amiga Basic uses to map
routine names to routine offsets in the library's jump table. It is intended
for the experienced programmer who needs this information to build a
LIBRARY of machine language routines for Amiga Basic. Since many
routines in libraries are written in assembly language and take their
arguments in registers, Amiga Basic also requires a way to know the register
calling conventions for each routine.
A special disk file must exist for every library to be attached to Amiga Basic
with the LIBRARY statement. This file must contain the information
described above. If the library is named" :Libs/graphics.library", then this
special file is named ":Libs/graphics.bmap." The .bmap extension indicates
that this is a special file that has been converted from its corresponding .fd
file. The format of a ".bmap" file is as follows:
Appendices A-19
For routines that follow C calling conventions and take their parameters on
the stack, the Register parameter is empty because Amiga Basic doesn't
need to pass any parameters in registers.
then a hexidecimal dump of the library's "bmap" file would look like this:
4D6F7665546FOOFFE8010200436C6561725261737400FFE20900
A-20 Appendices
Appendix G: A Sample Program
Here is a closer look at Picture, the program you ran in the practice session.
The bracketed letters are for your reference only. They do not appear in
your listing.
The following section describes line by line exactly what each statement in
Picture does.
[A] Basic will recognize variable names beginning with the letters P
through Z as integers.
[B] Creates an array with a dimension of 2500 elements.
[C] Erases the Output window.
[D] Draws a rectangle defined by points (0,0) and (120,120) and filled.
[E] Sets the variable ASPECT to 0.1.
Appendices A - 21
[F] Repeats the following as long as ASPECT is <20.
[G] Draws an ellipse with center (60,60), radius 55, color 0 (blue), and
an aspect ratio =ASPECT.
[H] Increases the value of ASPECT.
[I] Exits this loop when ASPECT> = 20.
[J] Copies the content of this part of the window to an array P.
[K] Starts a routine called CheckMouse to check the mouse status.
[L] Waits for the mouse Selection button to be pressed.
[M] If the mouse has moved at least 3 points in the X direction, the
program goes to MovePicture.
[N] If the mouse has moved at least 4 points in the Y direction, the
program goes to CheckMouse.
[0] Starts a routine called MovePicture to move the picture stored in
array P.
[P] Erases the picture from the old location.
[Q] Sets X and Y to the new coordinates of the mouse.
[R] Copies the picture in array P to the new X,Y location.
[S] Goes back to the CheckMouse routine.
A-22 Appendices
Appendix H: Writing Phonetically
for the Say Command
Narrator works on utterances at the sentence level. Even if you only want to
say only one word, Narrator treats it as a complete sentence. So, Narrator
asks for one of two punctuation marks to appear at the end of every
sentence: the period (.) and the question mark (?). If no punctuation
appears at the end of a string, Narrator automatically appends a period to it.
The period, used for almost all utterances, results in a final fall in pitch at
the end of the sentence.
The question mark, used only at the at the end of yes/no questions, results
in a final fall in pitch. So, the question, "Do you enjoy using your Amiga?"
takes a final question mark because the answer is a yes or a no. On the other
hand, the question, "What is your favorite color?" doesn't take a question
mark and is followed by a period. Narrator does recognize other forms of
punctuation, discussed later in this appendix.
Spelling Phonetically
Appendices A-23
two upper case letters. To specify phonetic sounds, Narrator uses an
expanded version of Arpabet.
Like letters, phonemes are divided into vowels and consonants. A vowel is a
continuous sound made with the vocal cords vibrating and with air exiting
the mouth (rather than the nose). All vowels use a two-letter code. A
consonant is any other sound, such as those made by rushing air (like S or
TH) or by interruptions in air flow by the lips and the tongue (like B or T).
Consonants use a one or a two-letter code.
Written English uses the five vowels a, e, i, 0, and u. On the other hand,
spoken English uses more than 15 vowels, and Narrator provides for most of
them. To choose a vowel properly, first listen to it. Say the word aloud,
perhaps extending the desired vowel sound. Then compare the sound you
are making to the vowel sounds in the example words to the right of the
phoneme list. For example the "a" in apple sounds the same as the "a" in
cat and not like the "a's" in Amiga, talk, or made. Note that some of the
example words in the list don't even use any of the same letters contained in
the phoneme code, for example, AA as in hot.
Vowels fall into two categories: those that maintain the same sound
throughout their durations and those that change their sounds.
"Diphthongs" are the ones that change. You may remember being taught
that vowel sounds were either long or short. Diphthongs are long vowels, but
they are more complex than that. Diphthongs are the last six vowels in the
A-24 Appendices
table. Say the word "made" aloud very slowly. Note how the a starts out
like the e in bet but ends up like the e in beet. The a is thus a diphthong in
this word and "EY" represents it. Some speech synthesizers make you
specify the changing sounds in diphthongs as separate elements. Narrator
assembles the diphthongal sounds for you.
Phoneticians divide consonants into many categories, but most of them are
not relevant. To pick the correct consonant, you only have to pay attention
to whether it is voiced or unvoiced. You make a voiced consonant with your
vocal cords vibrating and you make an unvoiced one with your vocal cords
silent. Written English sometimes uses the same letter combinations to
represent both. Compare the sound of "th" in thin and then. Note that you
make the "th" sound in thin with air rushing between the tongue and the
upper teeth. In the "th" in then, the vocal cords are also vibrating. The
voiced "th" phoneme is DH, the unvoiced is TH. So, the phonetic spelling
of thin is THIHN whereas then is DHEHN.
Another sound that causes confusion is the "r" sound. The Narrator
alphabet contains two r-like phonemes: R under the consonants and ER
under the vowels. If the r sound is the only sound in the syllable, use ER.
Examples of words that take ER are absurd, computer, and flirt. On the
other hand, if the r sound preceds or follows another vowel sound in the
syllable, use R. Examples of words that take R are car, write, or craft.
Appendices A-25
used and the AX phoneme is used instead. Since spoken English often
relaxes vowels, AX and IX phonemes occur frequently before 1, m, and n.
Narrator uses other special symbols internally and sometimes inserts them
into your input sentence or even substitutes them for part of it. If you wish,
you can type some of these symbols in directly. Probably the most useful is
the Q or glottal stop- an interruption of air flow in the glottis. The word
Atlantic contains one between the t and the 1. Narrator already knows there
should be one there and saves you the trouble of typing it. However, you
may stick in a Q if Narrator should somehow let a word or a word pair slip
by that would have sounded better with one.
Now that you've learned about telling Narrator what you want said, it's time
to learn to tell it how you want it said. You use stress and intonation to alter
the meaning of a sentence, to stress important words, and to specify the
proper accents in words with several syllables. All this makes Narrator's
output more intelligible and natural.
To specify stress and intonation, you use stress marks made up of the single
digits 1-9 followed by a vowel phoneme code. Although stress and
intonation are different things, you specify them with a single number.
Among other things, stress is the elongation of a syllable. So, stress is a
logical term--either the syllable is stressed or it is not. To indicate stress on
a given syllable, you place a number after the vowel in the syllable. Its
presence indicates that Narrator is to stress the syllable. To indicate the
intonation, you assign a value to the number. Intonation here means the
pitch pattern or contour of an utterance.
A-26 Appendices
The higher the stress marks the higher the potential for an accent in pitch.
The contour of each sentence consists of a quickly rising pitch gesture up to
the first stressed syllable in the sentence, followed by a slowly declining tone
throughout the sentence, and finally a quick fall to the lowest pitch on the
last syllable. Additional stressed syllables cause the pitch to break its slow
declining pattern with rises and falls around each stressed syllable. Narrator
uses a sophisticated procedure to generate natural pitch contours based on
your marking of the stressed syllables.
You place the stress marks directly to the right of the vowel phoneme codes.
For example, the stress mark on the word cat appears after the AE, so the
result is KAEST. Generally, there is no choice about the location of the
number. Either the number should go after a vowel or it shouldn't. Narrator
does not flag errors such as forgetting to include a stress mark or placing it
after the wrong vowel. It only tells you if a stress mark is in the wrong place,
such as after a consonant. Follow these rules to use stress marks correctly:
1. Place a stress mark in a content word, that is, one that contains
some meaning. Nouns, action verbs, and adjectives are all
content words. Tonsils, remove, and huge are all examples of
words that tell the listener what they're talking about. On the
other hand, words like but, if, is, and the are not content words.
They are, however, needed for the sentence to function and so
are called function words.
Appendices A-27
3. If more than one syllable in a word receives a stress mark,
indicate the primary and secondary stresses by marking
secondary stresses with a value of only 1 or 2. For example, the
word understood has its first and last syllables stressed with
stand getting primary stress and un getting secondary stress.
Thus the spelling would be AHINDERSTAE4ND.
After you've picked the spelling and the stress mark positions correctly, it's
time to decide on stress mark values. They are like parts of speech in
written English. Use this table to assign stress values:
Nouns 5
Pronouns 3
Verbs 4
Adjectives 5
Adverbs 7
Quantifiers 7
Exclamations 9
Articles 0 (no stress)
Prepositions 0
Conjunctions 0
Secondary Stress 1, sometimes 2
A-28 Appendices
Please deliver this to Mr. Smith
you'll indicate that the letter should be delivered to Mr. Smith in person.
Using Punctuation
The dash. is like the comma except that the pitch does not rise so severely.
Here's a rule of thumb: Use dashes to divide phrases and commas to divide
clauses. Parentheses provide additional information to Narrator's
intonation routine. Put them around noun phrases of two or more content
words, for example "giant yacht." Parentheses can be particularly effective
around large noun phrases like "the silliest guy I ever saw." They help
provide a natural contour.
Although this guide should get you off to a good start. the only sure way to
proficiency is to practice. Follow these tricks to inprove the intelligibility of
a sentence:
Appendices A-29
2. Keep sentences to an optimal length. Write for speaking rather
than for reading. Do not write a sentence that cannot be easily
spoken in one breath. Keep sentences confined to one idea.
3. Stress new terms highly the first time they are heard.
These techniques are but a few of the ways to enhance the performance of
Narrator. Undoubtedly, you'll find some of your own. Have fun.
Tables of Phonemes
Vowels
IY beet IH bit
EH bet AE bat
AA hot AH under
AO talk UH look
ER bird OH border
AX about IX solid
Diphthongs
EY made AY hide
OY boil AW power
OW low UW crew
A-30 Appendices
Consonants
R red L yellow
W away Y yellow
M men N men
NX sing SH rush
S sail TH thi
F fed ZH pleasure
Z has DH then
V very J judge
CH check IC loch
IH hole P put
B but T toy
D dog G guest
K Commodore
Special Symbols
Appendices A-31
aspect ratio,
1-1 Index
Continue, 3-10, 4-7 MENU, 6-14
conversion of numeric, 8-10 MOUSE, 6-14
Copy, 3-9 ON .. GOSUB, 6-14
copy key, 8-3 overview, 6-13
COS, 8-39 suspending, 6-15
CSNG, 8-40 terminating, 6-15
CSRLIN, 8-41 TIMER, 6-14
Cut, 3-9 EXIT SUB. 8-145
cut key, 8-3 exiting Amiga Basic, 3-2
CVD, 8-41 EXP, 8-51
CVI, 8-41 expressions, 8-11
CVL, 8-41
CVS, 8-41 FIELD, 8-52
filenames, valid, 5-3
DATA, 8-42 FILES, 8-53
data files, See files files,
data segment, modes, 8-101
conserving space in, 6-17 naming conventions, 5-5
definition, 6-17 opening, 5-5
setting size, 8-33, 6-16 saving, 5-5
using FRE with, 6-18 files, random,
DATES, 8-43 accessing, 5-15
debugging programs, 4-5 creating, 5-13
DECLARE FUNCTION, 8-43 example, 5-16
DEF FN, 8-44 overview, 5-12
DEFDBL, 8-46 files, sequential,
DEFINT. 8-46 adding data, 5-11
DEFLNG, 8-46 creating, 5-9
DEFSNG, 8-46 overview, 5-8
DEFSTR, 8-46 reading data from, 5-11
DELETE, 8-47, 8-28 FIX, 8-53
device names, 5-2 fixed-point constants, 8-6
DIM, 8-47 floating-point constants, 8-6
division FOR, 8-54
by zero, 8-14 FRE,
integer, 8-13 description, 8-55
double-precision constants, 8-7 in memory management, 6-18
function keys, Amiga, 8-3
Edit menu, 3-9 functions, types, 8-17
editing a program, how to, 4-1, 2-10
ELSE. 8-60 GET,
ELSEIF, 8-60 description, 8-56
END, 8-48 for random files, 8-56
END IF, 8-61 for screen data, 8-56
END SUB, 8-145 GOSUB, 8-58
See also subprograms GOTO. 8-59
Enlarge menu, in Object Editor, 7-6 graphics commands,
EOF, 8-48 AREA 8-21
EOV, 8-16 AREAFILL 8-21
ERASE. 8-49 CIRCLE 8-32
Erase, in Object Editor Tools menu, 7-6 COLOR 8-37
ERL, 8-49 LINE 8-70
ERR, 8-49 PAINT 8-102
ERROR, 8-50 PALETTE 8-103
error correction, 2-14 SCREEN 8-132
event trapping,
activating, 6-12 heap, See system heap
BREAK, 6-14 HEXS, 8-59
COLLISION, 6-14
Index 1-2
hexadecimal constants, 8-6 machine language programs,
high-resolution, setting, 8-133 See assembly language programs
memory management, 6-16
MENU,
IF .. GOTO, 8-60 description, 8-78
IF .. THEN .. ELSE, 8-60 in event trapping, 6-14
immediate mode, 3-4 See also ON MENU
IMP, 8-16 menu bar, displaying, 3-5
INKEY$, 8-63 MENU ON/OFF/STOP, 8-80
INPUT, 8-63, 8-101
menus,
INPUT#, 8-65
Edit, 3-9
INPUT$, 8-65
INSTR, 8-66 Project, 3-8
INT, 8-66 Run, 3-9
Windows, 3-11
integers,
declaring, 8-9 MERGE, 8-80, 8-28
MID$, 8-81
short and long, 8-6
MKD$, 8-82
MKI$, 8-82
KILL, 8-67 MKL$, 8-82
KYBD:, 5-2 MKS$, 8-82
MOD, 8-12, 8-14
labels, format and rules, 8-5 mode, screen, 8-134
LBOUND, MOUSE,
description, 8-67 description, 8-83
using in arrays, 6-8 in event trapping, 6-14
LEFT$, 8-68 See also ON MOUSE
LEN, 8-68 MOUSE ON/OFF/STOP, 8-86
LET, 8-69 mouse
libraries, position, 8-84
opening, 6-19 status, 8-85
overview, 6-18
LIBRARY, NAME, 8-87
description, 8-70 NEW, 8-87
with CALL, 8-26 New,
LINE, 8-70 in File menu, 3-8
Line, in Object Editor Tools menu, 7-5 in Object Editor File menu, 7-5
LINE INPUT, 8-71 NEXT, 8-54, 8-87
LINE INPUT#, 8-72 NOT,8-16
line numbers, 8-3
LIST, 8-73 Object Editor,
list key, 8-3
purpose, 7-2
List window, 2-9
how to use, 7-7
List window, selecting, 3-7 menus, 7-4
LLIST, 8-74
screen layout, 7-3
LOAD, 8-74
OBJECT.AX, 8-88
loading a program, 3-3 OBJECT.AY, 8-88
LOC, 8-75
LOCATE, 8-75 OBJECT. CLIP , 8-88
OBJECT. CLOSE, 8-88
LOF, 8-76
OBJECT. HIT, 8-89
LOG, 8-76
OBJECT. OFF, 8-90
loops, nested, 8-54
OBJECT.ON, 8-90
low-resolution, setting, 8-133 OBJECT .PLANES, 8-90
LPOS, 8-77
LPRINT, 8-77 OBJECT. PRIORITY, 8-90
OBJECT. SHAPE, 8-91
LPRINT USING, 8-77 OBJECT. START, 8-93
LPT1:, 5-2 OBJECT. STOP, 8-93
LSET, 8-78
OBJECT. VX, 8-93
OBJECT. VY, 8-93
OBJECT. X, 8-94
1-3 Index
OBJECT. Y, 8-94 PTAB, 8-119
objects, how to create, 7-7 PUT,
OCTS, 8-95 description, 8-120
octal constants, 8-6 for random files, 8-120
ON BREAK, 8-96 for screen data, 8-120
ON COLLISION, 8-96
ON ERROR GOTO, 8-97 Quit, in File menu, 3-8
ON .. GOSUB QUit, in Object Editor File menu, 7-5
description, 8-97
in event trapping, 6-14 random
ON .. GOTO, 8-97 files, 5-10 - 5-16
ON MENU, 8-98 GET, 8-56
ON MOUSE, 8-99 PUT, 8-120
ON TIMER, 8-99 RANDOMIZE, 8-121
OPEN, 8-100 READ, 8-122
Open, Rectangle, in Object"Editor Tools menu, 7-5
in File menu, 3-8 resolution, screen, 8-134
in Object Editor File menu, 7-5 REM, 8-122
operations, hierarchy, 8-12 RESTORE, 8-124
operators, RESUME, 8-124, 8-137
arithmetic, 8-12 RETURN, 8-124, 8-58
functional, 8-17 RIGHTS, 8-125
logical, 8-15 RND, 8-126
relational, 8-14, 8-18 RSET, 8-128
OPTION BASE, 8-101 RUN, 8-127
OR,8-16
Run menu, 3-9
OUTPUT, 8-101, 8-158
Output window, 2-7, 3-6
Oval, in Object Editor Tools menu, 7-5 SADD, 8-128
overflow, 8-14 SAVE, 8-128
Save,
PAINT, 8-1'02 in File menu, 3-8
Paint, in Object Editor File menu, 7-5
Save As,
in Object Editor Tools menu, 7-5 in File menu, 3-9
PALETTE, 8-103
parity, 5-2 in Object Editor File menu, 7-5
saving a program, 3-3, 2-21
Paste, 3-9 SAY, 8-129
paste key, 8-3 SCREEN,
PATTERN, 8-104
PEEK, 8-105 description, 8-132
using system heap, 6-17
PEEKL, 8-105 SCREEN CLOSE, 8-132
PEEKW, 8-106
screen mode, setting, 8-133
Pen, in Object Editor Tools menu, 7-5 SCRN:, 5-2
POINT, 8-106 SCROLL, 8-134
POKE, 8-106 scrolling program listings, 4-4, 2-8
POKEL, 8-107 selecting text, 4-3
POKEW, 8-108 sequential files, 5-7
POS, 8-108 SGN, 8-135
PRESET, 8-109 SHARED, 8-135, 6-4
PRINT, 8-109 Show List, in Windows menu, 3-11
PRINT USING, 8-111 Show Output, in Windows menu, 3-11
PRINT#, 8-116 SIN, 8-136
PRINT# USING, 8-116 single-precision constants, 8-7
printer device names, 5-3 SLEEP, 8-136
printers, using, 5-3 SOUND,
program files, 5-7 description, 8-137
program execution mode, 3-4 using system heap. 6-17
Project menu, 3-8 SPACES, 8-139
PSET, 8-119 SPC, 8-140
1-4 Index
speech, TAB, 8-148
using SAY, 8-129 TAN, 8-148
creating phonetic, A-23 THEN, 8-60
using TRANSLATES, 8-150 TIMES, 8-149
sprites, defining in Object Editor, 7-6 TIMER, in event trapping, 6-14
SQR, 8-141 TIMER ON/OFF/STOP, 8-150
stack, Trace Off, 3-10
conserving space in, 6-16 Trace On, 3-10
definition, 6-16 TRANSLATE$, 8-150
setting size, 8-33, 6-16 TROFF, 8-151
using FRE with, 6-18 TRON,
Start, 3-10 description, 8-151
start run key, 8-3 in debugging programs, 4-5
starting Amiga Basic, 3-2
Statement and Function Directory, 8-19
STATIC, 6-5, 8-145
STEP, 8-54, 8-70
Step option, in debugging programs, 4-6, 3-10
UBOUND,
description, 8-67, 8-151
using in arrays, 6-8
--
,
1-5 Index
----------------------------------------------------------------------------------~~--
--
COMMODORE::®
Commodore Business Machines, Inc.
1200 Wilson Drive' West Chester, PA 19380