100213-001 GW-BASIC Reference Manual 1984
100213-001 GW-BASIC Reference Manual 1984
Section 1
I ntrod uction
Graphics 1-1
Sound and Music 1-2
Input Peripherals Support 1-2
Device-I ndependent Input/Output 1-2
Event Trapping 1-3
ON ... GOSUB Statement Type 1-5
RETURN Statement 1-6
Keyword Entry Using the Alt Key 1-7
Section 2
General Information About GW-BASIC
Syntax Notation 2-1
Line Format 2-2
Error Messages 2-2
Modes of Operation 2-2
Default Disk Drive 2-3
Active and Visual (Display) Pages 2-3
Character Set 2-3
Constants 2-5
String Constants 2-5
Numeric Constants 2-5
Single/Double Precision Form for Numeric Constants 2-6
Variables 2-7
Variable Names and Declaration Characters 2-7
Array Variables 2-8
Memory Space Requirements 2-8
Type Conversion 2-9
iii
iv GW-BASIC Reference Manual
Section 3
Programming Animation
Animation Features 3-1
Programmable Motion and Priority 3-1
Multiple Object Views 3-2
Animation Event Statements 3-2
Animation Event Functions 3-3
Animation EVent Control Statements 3-4
Object Activation Statements 3-5
Overview of Animation Programming 3-5
Sample Animation Program Description 3-6
Initializing the System 3-7
Dimensioning the Object Arrays 3-7
Generating the Views for Each Object 3-8
Storing the Object Views in Arrays 3-8
Defining the Views Comprising an Object 3-9
Setting Up the Event Traps 3-9
Enabling the Event Traps 3-9
Defining Object Parameters and Activating the Object 3-10
Incuding the Background Program 3-10
Using ARR IVAL Subroutines 3-11
Using CLIP Subroutines 3-121,
Using COLLISION Subroutines 3-12
Contents v
Section 4
Starting GW-BASIC
Starting GW-BASIC Without MS-DOS 4-1
GW-BASIC Operating Environment Without MS-DOS 4-2
Starting GW-BASIC with MS-DOS 4-2
BASIC Command Line Syntax 4-3
Command Line Options 4-3
File Options 4-4
Option Switches 4-4
BASIC Command Examples 4-6
Redirection of Standard Input and .Standard Output 4-7
Rules for Redirecting Input and Output 4-7
Example of I/O Redirection 4-7
Returning to MS-DOS from GW-BASIC 4-8
Section 5
Editing Basic Programs
Line Editing 5-1
Edit Command 5-2
Full Screen Editor 5-2
Writing Programs 5-2
Editing Programs 5-3
Control Functions and Editor Keys 5-4
BASIC Editor Function Keys 5-4
Logical Line Definition with INPUT 5-6
Editing Lines Containing Variables 5-6
Section 6
GW-BASIC Commands, Statements, Functions,
and Variables
ABS Function 6-3
ACTIVATE/DEACTIVATE Statements 6-4
ARRIVAL Function 6-5
ARRIVAL Statement 6-8
ASC Function 6-10
ATN Function 6-11
AUTO Command 6-12
BEEP Statement 6-13
BLOAD Statement 6-14
BSAVE Statement 6-15
CALL Statement 6-16
CALLS Statement 6-17
CDBL Function 6-18
CHAI N Statement 6-19
CHOIR Statement 6-22
CH R$ Function 6-23
VI l.:iW-tiA::iIl,; Heterence Manual
CI NT Function 6-24
CI RCLE Statement 6-25
CLEAR Statement 6-27
CLIP Function 6-28
CLI P Statement 6-30
CLOSE Statement 6-31
CLS Statement 6-32
COLLISION Function 6-33
COLLISION Statement 6-36
COLOR Statement (Text) 6-37
COLOR Statement (Graphics) 6-39
COM Statement 6-41
COMMON Statement 6-42
CONT Command 6-43
COS Function 6-44
CSNG Function 6-45
CSRLlN Variable 6-46
CVI, CVS, and CVD Functions 6-47
DATA Statement 6-48
DATE$ Statement 6-49
DATE$ Variable 6-50
DEF FN Statement 6-51
DEFINT/SNG/DBL/STR Statements 6-52
DEF OBJ ECT Statement 6-53
DEF SEG Statement 6-54
DEF USR Statement 6-55
DELETE Command 6-56
01 M OBJ ECT Statement 6-57
DIM Statement 6-58
oRAW Statement 6-59
EDIT Command 6-62
END Statement 6-63
ENVI RON Statement 6-64
ENVI RON$ Function 6-66
EOF Function 6-68
ERASE Statement 6-69
ERDEV and ERDEV$ Variables 6-70
ERR and ERL Variables 6-71
ERROR Statement 6-72
EXP Function 6-74
FIELD Statement 6-75
FI LES Statement 6-78
FIX Function 6-80
FOR ... NEXT Statement 6-81
FRE Function 6-84
GET Statement (Files) 6-85
GET Statement (Graphics) 6-86
GOSUB ... RETURN Statements 6-88
Contents vii
Appendix A
Error Codes And Error Messages
GW-BASIC Error Messages A-1
Disk Error Messages A-5
Appendix B
Derived Mathematical Functions
AppendixC
ASCII Character Codes
Extended Codes C-3
Appendix D
GW-BASIC Reserved Words
Index
Figures and Tables
xi
Section 1
Introduction
You should read the Mindset Personal Computer Operation Guide before
using GW-BASIC. The Operation Guide explains how to power up the
system and how to insert cartridges, such as the one containing the
GW-BASIC interpreter.
Graphics
ACTIVATE COLLISION
ARRIVAL COLOR
CIRCLE DEACTIVATE
CLIP DEF OBJECT
1-1
1-2 GW-BASIC Reference Manual
The BEEP, PLAY, and SOUND statements enable use of the Mindset
Personal Computer sound capability. These statements are described
in Section 6, "GW-BASIC Commands, Statements, Functions, and
Variables" .
The BEEP statement operates through the internal beeper of the Mindset
Personal Computer while the PLAY and SOUND statements use its
external sound channel.
Device-Independent tnput/Output
BLOAD LOAD
BSAVE LOC
CHAIN LOF
CLOSE LPOS
ENVIRON LPRINT
ENVIRON$ MERGE
EOF NAME
ERDEV OPEN
ERDEV$ OPEN COM
FILES POS
GET PRINT
INPUT PRINT USING
INPUT$ PUT
10CTL RESET
10CTL$ RUN
KILL SAVE
LINE SHELL
LIST WIDTH
LLiST WRITE
Event Trapping
When a trap is made for a particular event, the trap automatically causes
a STOP on that event, so recursive traps can never occur. A return from
the trap routine automatically executes an ON statement unless an
explicit OFF has been performed inside the trap routine.
Note that after an error trap takes place, all trapping is automatically
disabled. You must explicitly re-enable trapping within the program
before another trap can occur. In addition, event trapping will never
occur when GW-BASIC is not executing a program.
RETURN Statement
When an event trap is in effect, a GOSUB statement will be executed as
soon as the specified event occurs. For example, the statement:
If not used with care, however, this capability may cause problems.
Assume, for example, that your program contains:
A- AUTO N - NEXT
B - BSAVE 0- OPEN
C - COLOR P - PRINT
D - DELETE Q - (no key word)
E - ELSE R-RUN
F - FOR S - SCREEN
G - GOTO T-THEN
H - HEX$ U - USING
I-INPUT V-VAL
J - (no key word) W-WIDTH
K- KEY X-XOR
L - LOCATE Y - (no key word)
M - (no key word) Z - (no key word)
Section 2
General Information
About GW-BASIC
Syntax Notation
< > Angle brackets indicate user-entered data. For example, enter
the name of your file when <filename> is shown in the format.
{} Braces indicate that the user has a choice between two or more
entries. At least one of the entries enclosed in braces must be
chosen unless the entries are also enclosed in square brackets.
2-1
2-2 GW-BASIC Reference Manual
All other punctuation, such as commas, colons, slash marks, and equal
signs, must be entered exactly as shown.
Line Format
More than one GW-BASIC statement may be placed on a line, but each
must be separated from the previous statement by a colon.
A GW-BASIC program line always begins with a line number and ends
with a carriage return. Line numbers indicate the order in which the
program lines are stored in memory. Line numbers are also used as
references in branching and editing. Line numbers must be in the range
a to 65529. A line may contain a maximum of 255 characters including
the line number.
You can extend a logical line over more than one physical line by
pressing the CTRL and RETURN keys simultaneously. CTRL-RETURN
lets you continue typing a logical line on the next physical line without
entering a carriage return.
A period (.) may be used in EDIT, LIST, AUTO, and DELETE commands
to refer to the current line.
Error Messages
Modes of Operation
later use, but the instructions themselves are lost after execution. Direct
mode is useful for debugging and for using GW-BASIC as a calculator
for quick computations that do not require a complete program.
Indirect mode is used for entering programs. Program lines are pre-
ceded by line numbers and may be stored in memory. The program
stored in memory is executed by entering the RUN command.
The size of these pages is set by the SCREEN statement (see Section 6).
Character Set
Character Action
Blank
Equal sign or assignment symbol
+ Plus sign
Minus sign
2-4 GW-BASIC Reference Manual
Character Action
Key Action
ESC Erases the line containing the cursor from the screen
and performs a carriage return. It does not delete
existing program lines from memory.
TAB Moves print position to next tab stop. Tab stops are set
every eight columns.
Constants
Constants are the values GW-BASIC uses during execution. There are
two types of constants: string and numeric.
String Constants
A string constant is a sequence of up to 255 alphanumeric characters
enclosed in double quotation marks.
Examples:
"HELLO"
"$25,000.00"
"Number of Employees"
Example:
Numeric Constants
Numeric constants are positive or negative numbers. They are stored
with 7 digits of precision and printed with up to 6 digits of precision.
GW-BASIC numeric constants cannot contain commas. There are six
types of numeric constants:
Examples:
235.988E - 7 = .0000235988
2359E6 = 2359000000
Examples:
&H76
&H32F
Examples:
&0347
&1234
A single precision constant is any numeric constant that has one of the
following characteristics:
Examples:
46.8
-1.09E-06
3489.0
22.5!
Examples:
345692811
-1.094320 - 06
3489.0#
7654321.1234
Variables
% Integer variable
! Single precision variable
# Double precision variable
Array Variables
An array is a group or table of values referenced by the same variable
name. Each element in an array is referenced by an array variable that is
subscripted with an integer or an integer expression. An array variable
name has as many subscripts as there are dimensions in the array. For
example, V(10) would reference a value in a one-dimensional array,
T(1,4) would reference a value in a two-dimensional array, and so on.
The maximum number of dimensions for an array is 255. The maximum
number of elements per dimension is 32,767.
Integer 2
Single precision 4
Double precision 8
General Information 2·9
Type Conversion
Example:
10 A%=23.42
20 PRINTA%
will yield
23
Examples:
10 D#=6#/7
20 PRINT D#
will yield
;8571428571428571
2-10 GW-BASIC Reference Manual
The arithmetic was performed in double precision and the result was
returned in D# as a double precision value.
10 D=6#/7
20 PRINT D
will yield
.857143
The arithmetic was performed in double precision, and the result was
returned to D (single precision variable), rounded, and printed as a
single precision value.
Example:
10 C%=55.88
20 PRINTC%
will yield
56
Example:
10A=2.04
20B#=A
30 PRINT A;B#
will yield
2.042.039999961853027
General Information 2-11
• Arithmetic
• Relational
• Logical
• Functional
Arithmetic Operators
The arithmetic operators, in order of evaluation, are:
Sample
Operator Operation Expression
1\
Exponentiation
Negation
Multiplication, Floating-
point division
The following list gives some sample algebraic expressions and their
GW-BASIC counterparts.
2-12 GW-BASIC Reference Manual
X+2Y X+Y*2
Y
X--
Z 'X-y/z
XY
Z X*Y/Z
X+Y
-Z (X+ Y)/Z
(X2)Y (XI\2)l\y
XyZ X 1\ (Y 1\ Z)
X (-Y) X*( - Y)
Examples:
10\4=2
25.68\6.99 = 3
Examples:
Relational Operators
Relational operators are used to compare two values. The result of the
comparison is either "true" (-1) or "false" (0). This result may then be
used to make a decision regarding program flow. (See the discussion of
IF statements in Section 6.)
Equal to X=y
<> Not equal to 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 the LET
. statement in Section 6.)
2-14 GW-BASIC Reference Manual
X+ Y«T -1) /Z
is true if the value of X plus Y is Jess than the value of T minus 1 divided
by Z.
More examples:
Logical Operators
Logical operators perform tests on multiple relations, bit manipulation, or
Boolean operations. The logical operator performs bit-by-bit calculation
and returns a result which is either "true" (not zero) or "false" (zero).
NOT
X NOT X
1 0
o 1
AND
xY XANDY
1 1 1
100
o1 0
000
OR
x Y XORY
1 1 1
1 01
o1 1
000
XOR
x Y XXORY
1 1 0
1 0 1
o1 1
000
General Information 2-15
EQV
XV XEQVV
1 1 1
1 a a
a1 a
aa 1
IMP
XV XIMPV
1 1 1
1 a a
a1 1
aa 1
Examples:
Functional Operators
When a function is used in an expression, it calls a predetermined
operation that is to be performed on an operand. GW-BASIC has
"intrinsic" functions that reside in the system, such as SQR (square root)
or SIN (sine). All GW-BASIC intrinsic functions are described in
Section 6.
String Operators
Strings may be concatenated by using the plus sign ( + ). For example:
10 A$ = "FILE" : B$ = "NAME"
20 PRINT A$ + B$
30 PRINT "NEW "+A$ + B$
will yield
FILENAME
NEW FILENAME
Strings may be compared using the same relational operators that are
used with numbers:
Examples:
'f\A"<'f\B"
"FILENAME" = "FILENAME"
"X&">"X#"
"CL" >"CL"
"kg">"KG"
"SMYTH" < "SMYTHE"
B$<"9/12/78" where B$ = "8/12/78"
<disk>
~~
SALESACCOUNTING
[*] - JOHN
/~ MARY STEVE
/\ SUE
REPORT
/1 other REPORT
I~other I~
other REPORT
~REPORT
files files files
Directory Paths
With GW-BASIC the user can organize a disk in such a manner that files
not part of the current task do not interfere with that task.
To specify a filename, the user could use one of two methods: either
specify a path from the root directory to the file, or specify a path from
the current directory to the file.
There is a special directory entry in each directory, denoted by'.. ' that is
the parent of the directory. The root directory's parent is itself.
Using a directory structure like the hierarchy above, and assuming that
the current directory is at point [*] (directory JOHN), to reference the
REPORT under JOHN, use any of the following paths:
REPORT
\SALES\JOHN\REPORT
.. \JOHN\REPORT
To refer to the REPORT under MARY, use either of the following paths:
.. \MARY\REPORT
\SALES\MARY\REPORT
To refer to the REPORT under SUE, use either of the following paths:
.. \ .. \ACCOUNTING\SUE\REPORT
\ACCOUNTING\SUE\REPORT
Disks formatted with versions of MS-DOS earlier than version 2.0 will
appear to MS-DOS 2.0 as having only a root directory containing files
but no subdirectories.
General Information 2-19
File-Naming Conventions
Filenames follow MS-DOS naming conventions. All filenames may begin
with a drive specification such as A: or B:. If no drive is specified, the
current drive is assumed. If no period (.) appears in the filename and the
filename is less than nine characters long, the default extension .BAS is
appended to filenames used in the LOAD, SAVE, MERGE and RUN
<filename> commands.
Examples:
RUN "NEWFILE.EXE"
RUN ''A:NEWFILE.EXE''
SAVE "NEWFILE" (file is saved with a .BAS extension)
Note that <filespec> still refers to [device:] <filename> and may not
contain directory names.
Example:
\SALES\JOHN\B:REPORT is not.
Initially, character device drivers for LPT1, LPT2, and LPT3 are installed
but may be replaced by the user. A line printer device may be opened
with the statement:
If a user writes and installs a device called FOO, then the OPEN
statement would appear as:
Such devices are OPENed and used in the same manner as disk files,
except that characters are not buffered by BASIC as they are for disk
files.
When the LEN = <Ireel> option is used, BASIC will buffer that many
characters before sending them to the driver.
4. When writing device drivers, remember that BASIC will want to read
and write control information.
5. Necessary control functions that your device driver must provide are:
b. Return the current maximum line width when BASIC asks for it.
For more information, see the discussions in Section 6 about the IOCTL
statement, the IOCTL$ function, and the device error variables EROEV
and EROEV$.
Memory Allocation
Memory space must be set aside for an assembly language subroutine
before the subroutine can be loaded. To set aside memory space, use
the 1M: switch during start-up. The 1M: switch sets the highest memory
location to be used by GW-BASIC.
• Skip over the first 512 bytes of the linker's output file (.EXE), and then
read in the rest of the file.
where <variable name> contains the segment offset that is the starting
point in memory of the subroutine being called.
• For each argument in the argument list, the two-byte offset of the
argument's location within the data segment (OS) is pushed onto the
stack.
• The GW-BASIC return address code segment (CS) and offset (IP) are
pushed onto the stack.
Figure 2-2 illustrates the state of the stack at the time the CALL
statement is executed. Figure 2-3 illustrates the condition of the stack
during execution of the called subroutine.
General Information 2-23
high argument a
addresses SP+4+(2*n)
high argument a
addresses argument 1
c
s 0
t u argument n
a n
c t argument n
k e return segment address
return offset
Stack pointer
local variables -(SP register
(data pushed on initial contents)
stack)
1. The called routine must preserve segment registers OS, ES, SS, and
BP. If interrupts are disabled in the routine, they must be re-enabled
before exiting. The stack must be cleaned up when the called routine
exits.
2. The called routine must know the number and length of the arguments
passed. The following assembly language routine shows an easy way
to refer to arguments:
PUSH BP
MOV BP,SP
ADD BP, (2* number of arguments) + 4
Then:
argument 0 is at BP
argument 1 is at BP-2
argument n is at BP-2* n
(number of arguments = n + 1)
20 A$ = "BASIC" + ,,,,
General Information 2-25
This addition forces the string literal to be copied into the string
space. Then the string may be modified without affecting the
program.
S. Data areas needed by the routine must be allocated either in the code
segment of the user routine or on the stack. It is not possible to
declare a separate data area in the user assembler routine.
Line 100 sets the segment to SOOO Hex. FOO is set to &H7FA by line 110
so the call to FOOwili execute the subroutine at location SOOO:7FA Hex
(absolute address S07FA Hex).
Important: The called program must know the variable type for the
numeric arguments passed. In the previous example, the instruction
MOVS WORD, copies only two bytes. This is fine if variables A and C
are integers. You would have to copy four bytes if the variables were
numbers in floating-point format.
When the USR function call is made, register AL contains a value that
specifies the type of argument given. The value in AL may be one of the
following:
Usually, the value returned by a USR function has the same type (integer,
string, or floating-point) as the argument that was passed to it.
The type (numeric or string) of the variable receiving the function call
must be consistent with that of the argument passed.
Section 3
Programming Animation
This section explains the basic techniques for using the GW-BASIC
animation statements and functions. A sample program included in this
section illustrates the use of the animation statements and functions
described later in Section 6, "GW-BASIC Commands, Statements,
Functions, and Variables."
Animation Features
3-1
3-2 GW-BASIC Reference Manual
The number of each object determines its viewing priority. When two
objects overlap, the object with the higher number is drawn on top of the
other object.
To define an object, the application program can first draw each view of
the object on the screen and then store the view in its own array, using
the graphics version of the GET statement. You can use the BSAVE
statement to save object arrays on disk and recall them later with a
BLOAD statement. You can use this technique to increase the effective
size of an animation program by creating and saving objects in a
separate program. You may also use any image generated external to
GW-BASIC, provided the format corresponds to an array produced by
the GET statement.
The DIM OBJECT statement simplifies the sizing of arrays for object
views. It enables you to specify the rectangle containing the view rather
than requiring you to calculate the number of words required for the
array. The SCREEN statement must establish the screen mode before
the DIM OBJECT statement can accurately calculate the number of
words required to contain the array.
After the object views are stored in arrays, the DEF OBJECT statement
logically links the arrays together to define an object. The object views
appear in the order listed in the DEF OBJECT statement. An array may
be used more than once in the definition for a single object. An array
may also be used in the definition of more than one object.
There are three forms of the ARRIVAL function (and three forms of the
CLIP and COLLISION functions as well): ARRIVAL( -1), ARRIVAL(O),
and ARRIVAL( <object number».
The first form of the ARR IVAL function, ARRIVAL( -1), returns -1 if one
or more objects have reached their destinations; it returns 0 otherwise.
This form of the function also latches the arrival status for the objects
which have arrived, providing a "snapshot" of the arrival status. This
snapshot enables the subroutines handling all arrived objects to be
executed without being confused by arrival events occurring after the
ARRIVAL( -1) function is executed.
The second form of the ARRIVAL function, ARRIVAL(O), is used after the
ARRIVAL( -1) function has latched the arrival status. It returns the
number of the lowest-numbered object which has arrived.
The ARRIVAL( <object number» form of the ARRIVAL function tests for
the arrival of a specific object. This function returns the object number if
the specified object has arrived; it returns 0 otherwise.
3-4 GW-BASIC Reference Manual
1. Call the ARRIVAL( -1) function to check for arrivals and to latch the
arrival status of any objects that have arrived. Here, the ARRIVAL( -1)
function returns - 1, indicating that some objects have arrived at their
destinations.
4. Call the ARR IVAL(O) function to determine the number of the next
arrived object. The ARRIVAL(O) function returns a value of 15 and
clears the arrival status of object 15. (Alternately, you could use the
ARRIVAL(15) form of the function to determine only if object 15 had
arrived.)
6. Call the ARR IVAL(O) function to determine the number of the next
arrived object. The ARRIVAL(O) function returns a value of 0, because
the arrival status of all objects has been cleared.
Suppose one or more arrivals took place while ARRIVAL STOP was in
effect. After the ARRIVAL ON statement is executed, the ON ARRIVAL
statement operates as if any remembered arrivals had just taken place,
Also, the ARRIVAL function will then return a value other than 0 for the
remembered arrivals,
1, Select the graphics display mode desired for animation, This step
must occur before using the DIM OBJECT statement.
3, Clear the screen and draw the views for each object on the screen,
10. Define the object parameters such as origin, destination, and speed.
The following subsections describe each of these steps and include the
appropriate sections of the sample animation program.
Each face follows a predefined path from the left side of the screen to the
right. At the right side of the screen, the faces are replaced with words
enclosed in a circle. These words then travel back to the positions
where the faces first appeared and the cycle begins again. The
program continues until any key is pressed.
The first face travels from left to right across the middle of the screen.
When it arrives at the right side of the screen, the word "DONE" replaces
the face and travels back to the left side of the screen. This procedure
demonstrates the use of the DIM OBJECT, DEF OBJECT, ON ARRIVAL,
ARRIVAL ON, OBJECT, ACTIVATE, and DEACTIVATE animation
statements.
The second face follows a zigzag path which intersects the path of the
first face. When the second face reaches the right side of the screen, the
word "CLIP" replaces the face and travels back to the left side of the
screen. In addition to the statements used with the first face, this
procedure demonstrates the use of the ON CLIP and CLIP ON state-
ments and the OBJECT function.
When the faces collide, they stop moving and the word "HIT" enclosed
within a circle overlays the point of collision between the two objects.
After a brief pause, the HIT circle disappears and the objects continue
Programming Animation 3-7
moving across the screen. This procedure demonstrates the use of the
ON COLLISION and COLLISION ON statements and how an object
overlays other objects with numerically lower object numbers.
10'
20 '
** **** ** SAMPLE ANIMATION PROGRAM ** ***
30'
40 '
** * ** INITIALIZE SYSTEM * *** *
50 CLS
60 SCREEN 2
65 KEY OFF 'Erase function key display
70 '
The sample program uses six views which appear in five objects. Table
3-1 lists the array names used in this program. The array names indicate
the object views which the arrays will contain.
80'
90 '
*** ** DIMENSION OBJECT ARRAYS * *** *
100 DIM OBJECT COLLlDED%(41, 19) , View for object 6
110 DIM OBJECT AGAPE%(41 ,19) , View 1 for objects 2 and 3
120 DIM OBJECT OPENED%(41, 19) , View 2 for objects 2 and 3
130 DIM OBJECT CLOSED%(41, 19) , View 3 for objects 2 and 3
140 DIM OBJECT ARRIVED%(41, 19) , View for object 5
150 DIM OBJECT CLiPPED%(41, 19) , View for object 4
,
160
170
180
'
'
*** ** DRAW OBJECTS ** ***
190 PRINT:PRINT:PRINTPRINT" CLIP HIT DONE" :LOCATE 13,9,0
200 ' Spaces for line 190: s sss ssss
210 CIRCLE(22,9),20,,-.7,-5.75 , Face with mouth agape
220 CIRCLE (22,3),2 , Eye for face with mouth agape
230 CIRCLE (76,9),20" - .3, - 5.9 , Opened mouth face
240 CIRCLE (83.4),2 , Eye for opened mouth face
250 CIRCLE (134,9),20" - .05, - 6.2 , Closed mouth face
260 CIRCLE (141,5),2 , Eye for closed mouth face
270 CIRCLE (22,27),20 , Circle to hold 'CLIP' word
280 CIRCLE (76,27),20 , Circle to hold 'HIT' word
290 CIRCLE (134,27),20 , Circle to hold 'DONE' word
300 '
310
320
'
'
*** ** STORE OBJECT VIEWS IN ARRAYS *****
330 GET (2,0) - (42, 18),AGAPE% , Store agape face
340 GET (56,0) - (96, 18),OPENED% , Store opened face
350 GET (114,0) - (154, 18),CLOSED% , Store closed face
360 GET (2,19)-(42,36),CLlPPED% , Store CLIP circle
370 GET (56,19) - (96,36),COLLlDED% , Store HIT circle
380 GET (114,19) - (154,36),ARRIVED% , Store DONE circle
390 '
Programming Animation 3-9
400
410
I
I
*** ** DEFINE VIEWS FOR EACH OBJECT * *** *
420 DEF OBJECT 6 AS COLLlDED% I 1 view
470 I
480
490
I
I
*** ** SET UP ANIMATION EVENT TRAPS * *** *
500 ON ARRIVAL (2) GOSUB 10000 I Subroutine for object 2 arrival
510 ON ARRIVAL (3) GOSUB 11000 I Subroutine for object 3 arrival
520 ON ARRIVAL (4) GOSUB 12000 I Subroutine for object 4 arrival
530 ON ARRIVAL (5) GOSUB 13000 I Subroutine for object 5 arrival
540 ON CLIP (3) GOSUB 14000 I Subroutine for object 3 clip
550 ON COLLISION GOSUB 15000 I Subroutine for object collisions
560 I
570
580
I
I
*** ** ENABLE EVENT TRAPPING * *** *
590 ARRIVAL ON I Enable arrival event trapping
600 CLIP ON I Enable clip event trapping
610 COLLISION ON I Enable collision event trapping
3-10 GW-BASIC Reference Manual
630
640
I
I
* * * * * SET OBJECTS 2 AND 3 IN MOTION * * * * *
650 OBJECT 2, 1 = 20,2 = 100,3 = 609,4 = 100,5 =.4,10 = 50 I Go left to right
680 OBJECT 3,1 = 20,2 = 180,3 = X2,4 = Y2,5 = .2,10 = 120 I Move up to peak
690 ACTIVATE 2,3 I Make 2 and 3 move
700 I
9999 I
10040 OBJECT 5,1 = 609,2 = 100,3 =20,4 = 100,9 = 1,10= 100' Set up object 5
10050 ACTIVATE 5 I Make object 5 move
10060 RETURN
10070 I
11000 I * * * * *OBJECT 3 ARRIVAL SUBROUTINE * * * * *
11010 I
11020 X3 = OBJECT(3,1) + 100 I Move object 3 right 100 units
11060
11070
DIRFLAG = DIRFLAG
RETURN
* (-1) I Toggle direction flag
11080
*** ** * *** *
I
12000 I
OBJECT 4 ARRIVAL SUBROUTINE
12010 I
13000
***** * *** *
I
13010 I
OBJECT 5 ARRIVAL SUBROUTINE
13020 I
14000 I
14010 I
*** ** OBJECT 3 CLIP SUBROUTINE **** *
14020 DEACTIVATE 3 I Vanish object 3
14080 RETURN
14090 I
310
320
I
I
*** ** STORE OBJECT VIEWS IN ARRAYS * ****
330 GET (2,0) - (42, 18),AGAPE% I Store agape face
340 GET (56,0) - (96, 18),OPENED% I Store opened face
350 GET (114,0) - (154, 18),CLOSED% I Store closed face
360 GET (2,19) - (42,36),CLlPPED% I Store CLIP circle
370 GET (56,19) - (96,36),COLLlDED% I Store HIT circle
380 GET (114,19) - (154,36),ARRIVED% I Store DONE circle
390
*** ** * *** *
I
400 I
DEFINE VIEWS FOR EACH OBJECT
410 I
470
*** ** * ****
I
480 I
SET UP ANIMATION EVENT TRAPS
490 I
570 I
ENABLE EVENT TRAPPI NG
580 I
630 I
SETOBJECTS2AND31N MOTION
640 I
680 OBJECT 3, 1 = 20,2 = 180,3 = X2,4 = Y2,5 = .2,10 = 120 I Move up to peak
690 ACTIVATE 2,3 I Make 2 and 3 move
700
710
720
I
I
** WAIT FOR USER TO PRESS A KEY TO END PROGRAM **
730 I Cursor is at line 13, column 9
9999 I
Programming Animation 3-15
10000
10020
I
I
*** ** OBJECT 2 ARRIVAL SUBROUTINE * *** *
10030 DEACTIVATE 2 I Vanish object 2
10040 OBJECT 5,1 = 609,2 = 100,3 = 20,4 = 100,9 = 1,10 = 100 I Set up object 5
10050 ACTIVATE 5 I Make object 5 move
10060 RETURN
10070
*** ** * *** *
I
11000 I
OBJECT 3 ARRIVAL SUBROUTINE
11010 I
11070 RETURN
11080
*** ** * *** *
I
12000 I
OBJECT 4 ARRIVAL SUBROUTINE
12010 I
13000
*** ** * *** *
I
13010 I
OBJECT 5 ARRIVAL SUBROUTINE
13020 I
14000 I
OBJECT 3 CLIP SUBROUTINE
14010 I
14080 RETURN
14090
***** *****
I
15000 I
OBJECT COLLISION SUBROUTINE
15010 I
16060 OBJECT 6,1 = XC,2 = YC,3 = XC + 1,4 = YC, 10 = 2,9 = 1 ' Move slowly
16070 COLLISION OFF: ACTIVATE 6 ' Make it visible
16080 START OBJECT 6 ' Start it moving
16090 WHILE (((ARRIVAL( -1 ))*ARRIVAL(6)) = 0): WEND I Wait for it to arrive
16100 DEACTIVATE 6 :COLLISION ON ' Make it disappear
16110 START OBJECT ' Restart the other objects
16120 RETURN
Section 4
Starting GW-BASIC
If you are using the cartridge version of GW-BASIC, you may run
GW-BASIC without MS-DOS,
Read the Mindset Personal Computer System Operation Guide if you are
unfamiliar with operating the Mindset configuration screen and using
cartridges,
4-1
4-2 GW-BASIC Reference Manual
If you are using a RAM cartridge to store BASIC programs and data, you
must insert the RAM cartridge in port 2 before pressing the ALT-RESET
keys.
When you press the ALT-RESET keys, the screen shown in Figure 4-1
appears.
GW-BASIC 2.0
(C) Copyright Microsoft 1983,1984
(C) Copyright Mindset 1983,1984
Version V1.0
60138 Bytes free
You may run GW-BASIC with MS-DOS using either the cartridge or
diskette version of GW-BASIC.
Starting GW-BASIC 4-3
To use the GW-BASIC cartridge with MS-DOS, enter the Mindset System
configuration screen and make Disk the first load priority. Next, place
the Mindset MS-DOS diskette in the left disk drive and place the Mindset
GW-BASIC cartridge in cartridge port 1. Then press the ALT-RESET keys
to load MS-DOS.
To start the diskette version of GW-BASIC, you must first load MS-DOS.
Refer to the Introductory Guide to MS-OOS or the MS-OOS Reference
Manual for instructions on how to load MS-DOS. After you load
MS-DOS, place the GW-BASIC diskette in the default drive.
There are eight options you can specify when GW-BASIC is started from
MS-DOS. These options, explained below, include device names, file
names, and option switches. An option switch always begins with a
forward slash (I) character.
You do not have to include any options to run most BASIC programs.
<stdin
BASIC input is redirected to come from the file specified by stdin. When
present, this syntax must appear before any switches.
>stdout
File Options
To specify the filename of a BASIC program file, include this option:
filename
Option Switches
You can use these option switches with the BASIC command.
If the IF and the II switches are present, then the maximum number of
files that may be open simultaneously during the execution of a BASIC
program is set to <number of files>. Each file requires 62 bytes for the
File Control Block (FCB), plus 128 bytes for the data buffer. The data
buffer size may be altered with the IS: option switch, described below. If
the IF: option is omitted, the number of files is set to 3.
The number of open files that MS-DOS supports depends upon the
value of the FILES = parameter in the CONFIG.SYS file. For GW-BASIC,
the parameter should be FILES = 10. Keep in mind that the first three are
taken by stdin, stdout, stderr, stdaux, and stdprn. One additional file is
needed by BASIC for LOAD, SAVE, CHAIN, NAME, and MERGE. This
leaves six for BASIC file 1/0; thus IF:6 is the maximum supported by
MS-DOS when FILES = 10 appears in the CONFIG.SYS file.
Attempting to OPEN a file after all the file handles have been exhausted
will result in a "Too many files" error.
IS: <Irecl>
If this switch and the II switch are present, the maximum record size
allowed for use with random files is set to <Ireel>.
Note: The record size option to the OPEN statement cannot exceed this
value. If the IS: option is omitted, the record size defaults to 128 bytes.
II
Memory location switch. When present, this switch sets the highest
memory location that will be used by BASIC. BASIC will attempt to
allocate 64K of memory for the data and stack segments. If machine
language subroutines are to be used with BASIC programs, use the 1M:
switch to set the highest location that BASIC can use. When omitted or
0, BASIC attempts to allocate all the memory it can, up to a maximum of
65536 bytes.
If you intend to load code or data above the highest location that BASIC
can use, enter the optional parameter <maximum block size> to
preserve space for them. This parameter is necessary if you intend to
use the SHELL statement. Failure to use this parameter will result in
COMMAND being loaded on top of your routines when a SHELL
statement is executed.
4-6 GW-BASIC Reference Manual
The 1M option can also be used to shrink the BASIC block to free more
memory for SHELling other programs. IM:,2048 says: 'f'\lIocate and use
32768 bytes maximum for data and stack". IM:32000,2048 allocates
32768 bytes maximum; BASIC will use only the lower 32000, leaving 768
bytes of extra memory.
Uses 64K of memory and 3 files to load and execute PAYROLL. BAS.
A>BASIC INVENT/F:6/1
A>BASIC IC:O/M:32768
Disables RS-232-C support and uses only 32K of data memory. The 32K
above that is free for the user.
A>BASIC II/F:4/S:512
A>BASIC TTY/C:512
6. BASIC will continue to trap keys from the keyboard when the ON KEY
(n) statement is used.
7. The printer echo key will not cause LPT1: echoing if standard output
has been redirected.
8. Typing CTRL-BRK will cause GW-BASIC to close any open files, issue
the message "Break in line <line number>" to standard output, exit
GW-BASIC, and return to MS-DOS.
9. When input is redirected, BASIC will continue to read from the new
input source until a CTRL-Z is detected. This condition may be tested
with the EOF function. If the file is not terminated by a CTRL-Z, or if a
BASIC file input statement tries to read past end-of-file, then any open
files are closed, the message "Read past end" is written to standard
output, and BASIC returns to MS-DOS.
Data read by INPUT and LINE INPUT will continue to come from the
keyboard. Data output by PRINT will go into the file DATA OUT.
Data read by INPUT and LINE INPUT will come from DATA.IN. Data
output by PRINT will continue to go to the screen.
Data read by INPUT and LINE INPUT will now come from the file
MYINPUTDAT and data output by PRINT will go into MYOUTPUTDAT
Data read by INPUT and LINE INPUT will now come from the file
\SALES\JOHN\ TRANS. DAT Data output by PRI NT will be appended to
the file \SALES\SALES.DAT
SYSTEM
Editing BASIC
Programs
GW-BASIC provides three ways to enter and edit text: you can use the
line editing capabilities, issue an EDIT command to place you in edit
mode, or use the full screen editor.
Line Editing
If the cursor is currently on a line, you can make the following changes.
If you are entering a line in response to an INPUT statement, you can
use only the first two items in this list:
• Delete an incorrect character from the line that is being typed. The
BACK SPACE key moves the cursor back one space and deletes a
character. The DEL key erases the character under the cursor. Use
the cursor movement keys to reach the character to be deleted.
• Delete the entire line that is being typed by pressing the ESC key. A
carriage return is executed automatically after the line is deleted.
5-1
5-2 GW-BASIC Reference Manual
Edit Command
The full screen editor gives you immediate visual feedback, so that
program text is entered in a "what you see is what you get" manner. You
can enter program lines, then edit an entire screen before recording the
changes. This time-saving capability is made possible by special keys
for cursor movement, character insertion and deletion, and line or
screen erasure. Specific functions and key assignments are discussed
in the following sections.
With the full screen editor, you can move quickly around the screen,
making corrections where necessary. The changes are entered by
placing the cursor on the first line changed and pressing RETURN at the
beginning of each line.
Writing Programs
You are using the full screen editor any time between the GW-BASIC
"Ok" prompt and the execution of a RUN command. Every line of text
that is entered is processed by the editor. Every line of text that begins
with a number is considered a program statement.
It is possible to extend a logical line over more than one physical line by
using the CTRL-RETURN sequence to produce a linefeed. A linefeed
causes subsequent text to start on the next line, without a carriage
return. A carriage return signals the end of the logical line; when a
carriage return is entered, the entire logical line is passed to GW-BASIC.
• A new line is added to the program. Addition of a line occurs if the line
number is valid (0 through 65529) and at least one non-blank
character follows the line number.
More than one statement may be placed on a line. If this is done, the
statements must be separated by a colon (:). The colon need not be
surrounded by spaces.
Editing Programs
Use the LIST command to display an entire program or range of lines on
the screen so that the lines can be edited with the full screen editor. Text
can then be modified by moving the cursor to the place where the
change is needed and then performing one of the following operations:
These actions are performed by special keys assigned to the various full
screen editor functions (see the next section, "Control Functions and
Editor Keys").
Changes to a line are recorded when the RETURN key is pressed while
the cursor is anywhere on that line. The RETURN key enters all changes
for that logical line, no matter how many physical lines are part of the
logical line and no matter where the cursor is located within the logical
line.
the line and the RETURN key was pressed, the message would be
passed to GW-BASIC as a direct mode statement and a syntax error
would result.
Hex Decimal
Code Code Key Function
Enter the ASCII control function by pressing the key listed while holding
down the CTRL key.
The CHR$ function may be used to perform these control functions. For
example, printing CHR$(30) moves the cursor up one line.
Previous word-CTRL- ..... moves the cursor left to the previous word. A
word is made up of the characters A-Z, a-z, or 0-9 and is delimited by a
space.
Next word-CTRL- ~ moves the cursor right to the next word. A word is
made up of the characters A-Z, a-z, or 0-9, and is delimited by a space.
Editing BASIC Programs 5-5
Linefeed-CTRL-RETURN moves the cursor to the next line but does not
insert a carriage return, so that the logical line can be continued.
The linefeed occupies one space on a line, always to the right of the last
character typed on a physical line. If there is no room on the physical
line, the linefeed is wrapped. The linefeed can be deleted, but it cannot
be typed over.
Cursor home-The HOME key moves the cursor to the upper left corner
of the screen. The screen is not blanked.
Append-The END key moves the cursor to the end of the line, without
deleting the characters passed over. All characters typed from the new
position until the RETURN key is pressed are appended to the logical
line.
Insert-The INS key is a toggle switch for insert mode. When insert
mode is on, characters are inserted at the current cursor position.
Characters to the right of the cursor move right as new ones are
inserted. Line wrap is observed.
Clear logical line-Pressing the ESC key anywhere in the line causes the
entire logical line to be erased.
~ -The ~ moves the cursor one position to the right. Line wrap is
observed .
.... -The .... key moves the cursor one position to the left. Line wrap is
observed .
• - The. key moves the cursor up one physical line in the current
column.
T-The T key moves the cursor down one physical line in the current
column.
5-6 GW-BASIC Reference Manual
The insert and delete modes move only characters that are within that
logical line. Delete mode decrements the size of the line.
Insert mode increments the logical line except when the characters
moved will write over non-blank charaoters that are on the same physical
line, but not part of the logical line. In this case, the non-blank
characters not part of the logical line are preserved and the characters
at the end of the logical line are thrown out. This preserves labels that
existed prior to the INPUT statement.
GW-BASIC Commands,
Statements, Functions,
and Variables
This section describes the GW-BASIC commands, statements, func-
tions, and variables in alphabetical order. Briefly, these elements can be
defined as:
Argument Meaning
6-1
6-2 GW-BASIC Refe.rence Manual
PURPOSE:
Tells what the instruction or function is used for.
SYNTAX:
Shows the correct syntax for the instruction or function. See the
introduction to this manual for syntax notation.
NOTES:
Describe in detail how the instruction or function is used.
EXAMPLES:
Shows sample programs or program segments that demonstrate the
use of the instruction or function.
Commands, Statements, Functions, and Variables 6-3
ABS FUNCTION
PURPOSE:
Returns the absolute value of the expression X.
SYNTAX:
Y = ABS(X)
EXAMPLE:
The function:
will yield:
35
6-4 GW-BASIC Reference Manual
ACTIVATE/DEACTIVATE STATEMENTS
PURPOSE:
ACTIVATE starts the motion of one or more objects. DEACTIVATE stops
the motion of one or more objects and removes them from the screen.
SYNTAX:
ACTIVATE [ <object number 1>[, <object number 2> ... ]]
DEACTIVATE [<object number 1>[, <object number 2> ... ]]
<object number 1> and <object number 2> are the numbers of the
objects being set into motion by the ACTIVATE statement or being
stopped and removed from the screen by the DEACTIVATE statement.
NOTES:
The objects specified in an ACTIVATE statement must be previously
defined with a DEF OBJECT statement.
If no object numbers are specified, ACTIVATE sets all objects into motion
and DEACTIVATE stops and removes all objects from the screen.
See also the START OBJECT and STOP OBJECT statements in this
section.
EXAMPLES:
The statement:
10 ACTIVATE 7,2,5
20 DEACTIVATE
stops the motion of all objects on the screen and removes them from
view.
Commands, Statements, Functions, and Variables 6-5
ARRIVAL FUNCTION
PURPOSE:
Returns the arrival status of an object.
SYNTAX:
X = ARRIVAL( -1)
X = ARRIVAL(O)
X = ARRIVAL( <object number»
<object number> is the number of a specific object to be tested for
possible arrival at its destination.
NOTES:
The ARRIVAL function enables a program to test for the arrival of an
object at its destination. The operation of the ARRIVAL function is similar
to that of the CLIP and COLLISION functions.
The ARRIVAL( -1) form of the ARRIVAL function latches the current state
of the arrival flags for all objects which have arrived since the last time
the arrival flags were latched. If any of the arrival flags for active objects
are set, then the ARRIVAL( -1) function returns -1, makes a copy of the
affected arrival flags, and clears the arrival flags so that they can be set
again. If no object has arrived at its destination since the last time the
arrival status was latched, the ARRIVAL( -1) function returns O.
After using the ARRIVAL( -1) function, the ARRIVAL(O) function can be
used to return the lowest numeric object which has the copy of its arrival
flag set. After returning this number, GW-BASIC clears the copy of the
arrival flag. The ARRIVAL(O) form of the ARRIVAL function returns 0 if the
copies of all arrival flags set by the ARRIVAL( -1) function have been
cleared by a corresponding number of ARRIVAL(O) functions.
EXAMPLES:
The following program uses line 100 to latch the arrival flags for all
objects. Line 110 obtains the number of the lowest numbered object
which has arrived at its destination. Line 120 checks the copies of the
arrival flags to see if any are still set. Line 130 selects the subroutine
corresponding to the object number returned in line 110.
If both objects 1 and 2 have arrived since the last time their flags were
latched, then line 110 places a value of 1 in X and clears the copy of the
arrival flag for object 1. After executing the subroutine at line 1000 and
returning to line 110, the ARRIVAL(O) function places a value of 2 in X
because the arrival flag for object 1 has been cleared. Line 130 then
transfers control to the subroutine at line 2000.
990 END
1000 'Subroutine for arrival of object 1
1990 RETURN
2000 'Subroutine for arrival of object 2
2990 RETURN
Commands, Statements, Functions, and Variables 6-7
990 END
1000 'Subroutine for arrival of object 1
1990 RETURN
2000 'Subroutine for arrival of object 2
2990 RETURN
6-8 GW-BASIC Reference Manllal
ARRIVAL STATEMENT
PURPOSE:
The ARRIVAL ON statement enables arrival testing. An arrival occurs
when an object arrives at the destination specified in an OBJECT
statement.
The ARRIVAL STOP statement suspends arrival testing until the next
ARRIVAL ON statement is executed.
SYNTAX:
ARRIVAL ON
ARRIVAL OFF
ARRIVAL STOP
NOTES:
The ARRIVAL ON statement enables arrival testing by an ON ARRIVAL
statement (see "ON ARRIVAL Statement" later in this section) as well as
polling of the arrival status using the ARRIVAL function. While the
ARRIVAL ON statement is in effect, and if a non-zero line number has
been specified in the ON ARRIVAL statement, GW-BASIC checks after
the execution of every statement to see if any of the specified arrival
events has occurred.
EXAMPLES:
The statement:
10 ARRIVAL ON
20 ARRIVAL OFF
Commands, Statements, Functions, and Variables 6-9
30 ARRIVAL STOP
suspends arrival testing. Arrival events which occur after this ARRIVAL
STOP statement are trapped after the next ARRIVAL ON statement is
executed.
6-10 GW-BASIC Reference Manual
ASC FUNCTION
PURPOSE:
Returns a numeric value that is the ASCII code for the first character of
the string X$. (See Appendix C, 'ASCII Character Codes", for ASCII
codes.)
SYNTAX:
Y = ASC(X$)
NOTES:
If X$ is null, an "Illegal function call" error is returned.
EXAMPLE:
The function:
10 X$ = "TEST"
20 PRINT ASC(X$)
will yield:
84
See "CHR$ function" later in this section for details on ASCII-to-string
conversion.
Commands, Statements, Functions, and Variables 6-11
ATN FUNCTION
PURPOSE:
Returns the arctangent of X, where X is in radians. The result is in the
range - pi/2 to pi/2 radians.
SYNTAX:
Y = ATN(X)
NOTES:
The expression X may be any numeric type, but the evaluation of ATN is
always performed in single precision.
EXAMPLE:
The function:
10 INPUT X
20 PRINT ATN(X)
will yield:
73
1.249046
6-12 GW-BASIC Reference Manual
AUTO COMMAND
PURPOSE:
Generates line numbers automatically during program entry.
SYNTAX:
AUTO [<line number>[, <increment> II
NOTES:
AUTO begins numbering at <line number> and increments each
subsequent line number by <increment>. The default for both values is
10. If <line number> is followed by a comma but <increment> is not
specified, the last increment specified in an AUTO command is
assumed.
EXAMPLE:
AUTO 100,50
AUTO
BEEP STATEMENT
PURPOSE:
Sounds the speaker at 800 Hz for 1/4 second,
SYNTAX:
BEEP
NOTES:
The BEEP statement sounds the ASCII bell code, This statement has the
same effect as PRINT CHR$(7).
EXAMPLE:
20 IF X < 20 THEN BEEP
BLOAD STATEMENT
PURPOSE:
Loads a specified memory image file into memory from disk or RAM
cartridge.
SYNTAX:
BLOAD <filespec> [, <offset> 1
NOTES:
The BLOAD statement allows a program or a block of data that has been
saved as a memory image file to be loaded anywhere in memory. A
memory image file is a byte-for-byte copy of what was originally in
memory. See "BSAVE Statement" in this section for information about
saving memory image files.
If the offset is omitted, the segment address and offset contained in the
file (that is, the address specified by the BSAVE statement when the file
was created) are used. Therefore,. the file is loaded into the same
location from which it was saved.
If offset is specified, the segment address used is the one given in the
most recently executed DEF SEG statement. If no DEF SEG statement
has been given, the GW-BASIC data segment will be used as the default
(because it is the default for DEF SEG).
EXAMPLE:
10 'Load subroutine at 600:FOOO
20 DEF SEG = &H600 'Set segment to 600 Hex
30 BLOAD"PROG1",&HFOOO 'Load PROG1
This example sets the segment address at 600 Hex and loads PROG1 at
FOOO.
Commands, Statements, Functions, and Variables 6-15
BSAVE STATEMENT
PURPOSE:
Saves the contents of the specified area of memory as a disk or RAM
cartridge file.
SYNTAX:
BSAVE <filespec>, <offset>, <length>
NOTES:
The BSAVE statement enables data or programs to be saved as memory
image files on disk. A memory image file is a byte-far-byte copy of what
is in memory.
If the offset is omitted, a "Syntax error" is issued and the save is aborted.
A DEF SEG statement must be executed before BSAVE. The last known
DEF SEG address will be used for the save.
EXAMPLE:
10 'Save PROG1
20 DEF SEG = &H6000
30 BSAVE"PROG1",&HFOOO,256
This example saves 256 bytes, starting at 6000: FOOO in the file PROG1.
6-16 GW-BASIC Reference Manual
CALL STATEMENT
PURPOSE:
Calls an external assembly language subroutine or a compiled routine
written in another high-level language.
SYNTAX:
CALL <variable name>[«argument list»]
NOTES:
The CALL statement transfers program flow to an external subroutine.
(See also "USR function" later in this section.) CALL passes unseg-
mented addresses.
The CALL statement generates the same calling sequence used by the
Microsoft BASIC compiler (see 'I\ssembly Language Subroutines" in
Section 2).
EXAMPLE:
110 MYROUT = &H 0000
120 CALL MYROUT(I,J,K)
Commands, Statements, Functions, and Variables 6-17
CALLS STATEMENT
PURPOSE:
Calls an external assembly language subroutine or a compiled routine
written in another high-level language.
SYNTAX:
CALLS <variable name>[«argument list»]
NOTES:
The CALLS statement works just like CALL, except that the segmented
addresses of all arguments are passed. (CALL passes unsegmented
addresses.) Because all FORTRAN parameters are call-by-reference
segmented addresses, CALLS should be used when accessing routines
written with FORTRAN calling conventions.
To locate the routine being called, CALLS uses the segment address
defined by the most recently executed DEF SEG statement.
6-18 GW-BASIC Reference Manual
COBl FUNCTION
PURPOSE:
Converts X to a double precision number.
SYNTAX:
Y = CDBL(X)
NOTES:
X can be either an integer or a single precision number.
EXAMPLE:
10 A=454.67
20 PRINT A; CDBL (A)
will yield:
454.67454.6700134277344
Commands, Statements, Functions, and Variables. 6-19
CHAIN STATEMENT
PURPOSE:
Calls a program and pass variables to it from the current program.
SYNTAX:
CHAIN [MERGE ]<filespec>[,[ <line number exp>]
[,ALL][,DELETE <range>]]
NOTES:
<filespec> is the file specification of the program called.
If the ALL option is used and <line number exp> is not, a comma must
hold the place of <line number expr>.
For example,
CHAIN "NEXTPROG""ALL
is correct;
CHAIN "NEXTPROG",ALL
The CHAIN statement with the MERGE option leaves the files open and
preserves the current OPTION BASE setting. A CHAINed program may
have an OPTION BASE statement if no arrays are passed.
If the MERGE option is omitted, CHAIN does not preserve variable types
or user-defined functions for use by the CHAINed program. That is, any
DEFINT, DEFSNG, DEFDBL, DEFSTR, or DEFFN statements containing
shared variables must be restated in the CHAINed program.
EXAMPLES:
Example 1:
Example 2:
Example 3:
CHOIR STATEMENT
PURPOSE:
To change the current MS-OOS directory.
SYNTAX:
CHOIR <pathname>
NOTES:
CHOIR works exactly like the DOS command CHOIR.
EXAMPLES:
The following CHOIR statements make SALES the current directory on
drive A, and INVENTORY the current directory on drive B:
Now that the current directory is SALES, MKOIR can be used to create
subdirectories JOHN and MARY.
MKOIR ',\SALES\JOHN"
CHOIR "JOHN"
or:
CHOIR ',\SALES\JOHN"
Commands, Statements, Functions, and Variables 6-23
CHR$ FUNCTION
PURPOSE:
Returns a string corresponding to the ASCII character number entered
as an argument. (ASCII codes are listed in Appendix C, '1\SCII
Character COdes".)
SYNTAX:
X$ = CHR$(I)
NOTES:
CHR$ is commonly used to send a special character. For instance, the
BELL character (CHR$(7)) could be sent as a preface to an error
message; also, a form feed (CHR$(12)) could be sent to clear the screen
and return the cursor to the home position.
EXAMPLE:
The function:
PRINT CHR$(66)
will yield:
CINT FUNCTION
PURPOSE:
Converts X to an integer by rounding the fractional portion.
SYNTAX: \
Y = CINT(X)
NOTES:
If X is not in the range - 32768 to 32767, an "Overflow" error occurs.
See the CDBL and CSNG functions in this section for details on
converting numbers to the double precision and single precision data
types, respectively. See also the FIX and INT functions, both of which
return integers.
EXAMPLE:
The function:
PRINT CINT(45.67)
will yield:
46
Commands, Statements, Functions, and Variables 6-25
CIRCLE STATEMENT
PURPOSE:
Draws an ellipse with the center and radius specified.
SYNTAX:
CIRCLE «xcenter>, <ycenter», <radius>
[, <color>[, <start>, <end>[, <aspect> ][,CFJ]]
<color> is the numeric symbol for the color desired (see "COLOR
Statement" later in this section). The default color is the foreground color.
<start> and <end> are the start and end angles in radians with the
range - 21T to 21T. These angles allow the user to specify where an
ellipse will begin and end. If the start or end angle is negative, the
ellipse will be connected to the center point with a line, and the angles
will be treated as if they were positive. Note that this is different from
adding 2 1T. The start angle may be less than the end angle.
<aspect> is the aspect ratio; that is, the ratio of the x radius to the y
radius. When default ratios are specified for the corresponding screen
mode, a circle is drawn. The default aspect ratios are 5/6 for 320 x 200
resolution screen mode and 5/12 for 640 x 200 resolution screen mode.
These default aspect ratios produce circles on display screens with a
standard aspect ratio of 4/3.
If the aspect ratio is less than one, the radius given is the x radius. If it is
greater than one, the y radius is given.
The CF option will cause the ellipse to be filled, just as the BF option
causes the box to be filled in the LINE statement. (See the LINE
statement later in this section.)
NOTES:
The last point referenced after a circle is drawn is the center of the circle.
For example, if the most recent point referenced was (0,0), STEP (10,5)
would reference a point at offset 10 from x and offset 5 from y.
EXAMPLE:
Assume that the last point plotted was 100,50. Then:
CIRCLE (200,200),50
and:
will both draw a circle at 200,200 with radius 50. The first example uses
absolute notation; the second uses relative notation.
Commands, Statements, Functions, and Variables 6-27
CLEAR STATEMENT
PURPOSE:
Sets all numeric variables to zero and all string variables to null, and
closes all open files; also, optionally, sets the end of memory and the
amount of stack space. The CLEAR statement also cancels the defini-
tion of all animation objects visible on the screen.
SYNTAX:
CLEAR [, [ <expression1 > H, <expression2> ]]
NOTES:
The CLEAR statement performs the following actions:
The CLEAR statement also affects visible objects defined with the DEF
OBJECT statement. Any object which has been located on the screen
with an OBJECT statement and made visible with an ACTIVATE state-
ment is stopped and removed from the screen by the CLEAR statement.
In other words, the CLEAR statement performs an implicit DEACTIVATE
statement.
EXAMPLES:
CLEAR
CLEAR ,32768
CLEAR ,,2000
CLEAR ,32768,2000
6-28 GW-BASIC Reference Manual
CLIP FUNCTION
PURPOSE:
Returns the clipping status of an object.
SYNTAX:
X = CLlP(-1)
X = CLlP(O)
X = CLlP«object number»
NOTES:
The CLIP function enables a program to test for the clipping of an object
at the boundary of the current window. The operation of the CLIP
function is similar to that of the ARRIVAL and COLLISION functions.
The CLIP function always returns 0 if the CLIP ON statement has not
been executed.
The CLlP( -1) form of the CLIP function latches the current state of the
clip flags for all objects which have been clipped since the last time the
clip flags were latched. If any of the clip flags for active objects are set,
then the CLlP( -1) function returns -1, makes a copy of the affected clip
flags, and clears the clip flags so that they can be set again. If no object
has exceeded the boundary of the current window since the last time the
clip status was latched, the CLlP( -1) function returns O.
After using the CLlP( -1) function, the CLlP(O) function can be used to
return the lowest numeric object which has the copy of its clip flag set.
After returning this number, GW-BASIC clears the copy of the clip flag.
The CLlP(O) form of the CLIP function returns 0 if the copies of all clip
flags set by the CLlP( -1) function have been cleared by a correspond-
ing number of CLlP(O) functions.
The third form of the CLIP function, CLlP( <object number», is also
used after using the CLlP( -1) function to make copies of all currently
set clip flags. This form of the function returns the object number if the
copy of that object's clip flag is set (it also clears the copy of the flag).
Otherwise, the CLIP «object number» function returns a value of O.
Commands, Statements, Functions, and Variables 6-29
The ON CLIP statement automatically latches the clip flags and makes
copies for testing with the CLlP(O) and CLlP( <object number» func-
tions before performing a GOSUB. Thus, the CLlP( -1) function is not
required before testing the copies of the CLIP flags within such a
subroutine.
Also see the CLIP statement for more information on testing for the
clipping of objects.
EXAMPLES:
The following program uses line 100 to latch the clip flags for all objects.
Line 110 sets a FOR-NEXT loop to test the copies of the clip flags of all
16 possible objects. Line 120 tests the copy of the clip flag for object K.
Line 130 causes the program to test the next object's clip flag if the clip
flag for object K was not set since the last time line 100 was executed.
Line 140 transfers control to the subroutine associated with object K.
The K in line 140 could be replaced with N because they will both
contain the same number. Line 160 terminates the FOR-NEXT loop.
100IFCLlP(-1) = OTHEN170
11OFORK = 1 T016
120 N = CLlP(K)
130 IF N = 0 THEN 160
140 ON K GOSUB 1000,2000
150 GOSUB 3000
160 NEXT K
170 'Remainder of main program
990 END
1000 'Subroutine for clipping of object 1
1990 RETURN
2000 'Subroutine for clipping of object 2
2990 RETURN
3000 'Subroutine for clipping of all objects
3990 RETURN
6-30 GW-BASIC Reference Manual
CLIP STATEMENT
PURPOSE:
The CLIP ON statement enables clip testing. Clipping occurs when an
object exceeds the boundary of the current window.
The CLIP STOP statement suspends clipping testing until the next CLIP
ON statement is executed.
SYNTAX:
CLiPON
CLIP OFF
CLIP STOP
NOTES:
The CLIP ON statement enables clip testing by an ON CLIP statement
(see "ON CLIP Statement" later in this section) as well as polling of the
clipping status using the CLIP function. While the CLIP ON statement is
in effect, and if a non-zero line number has been specified in the ON
CLIP statement, GW-BASIC checks after the execution of every state-
ment to see if any of the specified clipping events has occurred.
The CLIP OFF statement disables the testing for clipping by an ON CLIP
statement. Clipping that occurs after a CLIP OFF statement has been
executed is not discovered.
The CLIP STOP statement suspends clip testing. Clipping that occurs
after this statement is remembered and trapped after the next CLIP ON
statement is executed.
EXAMPLES:
The statement:
10 CLIP ON
20 CLIP OFF
30 CLIP STOP
suspends clip testing. Clipping events that occur after this CLIP STOP
statement are trapped after the next CLIP ON statement is executed.
Commands, Statements, Functions, and Variables 6-31
CLOSE STATEMENT
PURPOSE:
Concludes 110 to a file. The CLOSE statement complements the OPEN
statement.
SYNTAX:
CLOSE [[#]<file number>[,[#]<file number> ... ]]
NOTES:
<file number> is the number under which the file was opened. A
CLOSE with no arguments closes all open files.
A CLOSE for a sequential output file writes the final buffer of output.
The f;ND statement and the NEW command also close all disk files
automatically. (STOP does not close disk files.)
EXAMPLES:
CLOSE #1,#2
CLOSE 1,2
6-32 GW-BASIC Reference Manual
CLS STATEMENT
PURPOSE:
Erases the contents of the entire current screen.
SYNTAX:
CLS
NOTES:
The screen may also be cleared with the control sequence CTRL-L.
EXAMPLE:
10 CLS 'Clears the screen
Commands, Statements, Functions, and Variables 6-33
COLLISION FUNCTION
PURPOSE:
Returns object collision status.
SYNTAX:
X = COLLISION( -1)
X = COLLISION(O)
X = COLLISION«object number»
X = COLLISION( <object number 1>, <object number 2»
<object number> is the number of a specific object to be tested for a
possible collision with another object.
NOTES:
The COLLISION function enables a program to test for the collision of
one object with another. The operation of the COLLISION function is
similar to that of the ARRIVAL and CLIP functions.
The COLLISION( -1) form of the COLLISION function latches the current
state of the collision flags for all objects which have collided since the
last time the collision flags were latched. If any of the collision flags for
active objects are set, then the COLLISION( -1) function returns -1,
makes a copy of the affected collision flags, and clears the collision
flags so that they can be set again. If no object has collided since the
last time the collision status was latched, the COLLISION( -1) function
returns O.
After using the COLLISION ( -1) function to make copies of all currently
set COLLISION flags, the third form of the COLLISION function,
COLLISION «object number» can be used. This form of the function
returns the value of the lowest-numbered object which collided with
<object number> (it also clears the flag for this collision pair). This form
of the function returns 0 if no object collided with <object number>.
continued on next page
6-34 GW-BASIC Reference Manual
See the COLLISION statement for more information on testing for object
collisions.
EXAMPLES:
The following program uses line 100 to latch the COLLISION flags for all
objects and to transfer control to the subroutine at line 1000. Line 1000
sets N equal to the number of the lowest-numbered object involved in a
collision since the last time the collision status was latched. Line 1000
also clears the copy of the collision flag for object N. Line 1010 returns
control to the main program if the copies of the collision flags for all
objects are cleared. Line 1040 prints the numbers of the objects which
have collided. After line 1030 returns the program to line 1000, the
subroutine prints the number of the next object which has collided.
990 END
1000 N = COLLISION(O)
1010 IF N = 0 THEN RETURN
1020 M = COLLISION(N)
1030 IF M = 0 THEN 1000
1040 PRINT "Objects" N "and" M "have collided"
1050 GOTO 1020
If objects 2 and 15 and objects 10 and 5 have collided since the last time
the collision status was latched, this program would print the following
messages:
The statement:
10 X = COLLISION(3)
sets X to the number of the lowest-numbered object which collided with
object number 3. This example sets X to zero if no collisions with object
3 have occurred. The statement:
20 X = COLLISION(O)
30 X = COLLISION( -1)
latches the current collision information. This statement sets X to -1 if at
least one collision has occurred. Otherwise this statement sets X to O.
The statement:
40 X = COLLISION(3,4)
sets X to 4 if a collision between objects 3 and 4 has occurred and sets X
to 0 if no collision has occurred.
6-36 GW-BASIC Reference Manual
COLLISION STATEMENT
PURPOSE:
The COLLISION ON statement enables object collision testing.
The COLLISION OFF statement disables the testing for object collisions.
SYNTAX:
COLLISION ON
COLLISION OFF
COLLISION STOP
NOTES:
The COLLISION ON statement enables collision testing by an ON
COLLISION statement (see "ON COLLISION Statement" later in this
section) as well as polling of the collision status using the COLLISION
function .. While the COLLISION ON statement is in effect, and if a non-
zero line number has been specified in the ON COLLISION statement,
GW-BASIC checks after the execution of every statement to see if any
specified collisions have occurred.
EXAMPLES:
The statement:
10 COLLISION ON
20 COLLISION OFF
30 COLLISION STOP
PURPOSE:
Selects from the color palette the colors for the foreground text,
background, and screen border.
SYNTAX:
COLOR [<foreground>][.[ <background>][, <border>]]
<foreground> is the color for text. <background> is the color for the
background behind the text. <border> is the color of the border at the
edge of the display area.
NOTES:
The numbers used to specify the <foreground>, <background>, and
<border> colors refer to locations in the color palette of the Mindset
Personal Computer. A given color index value may not always produce
the same color because the colors in the palette can be reassigned
using the PALETTE and PALETTE USING statements. Table 6-1
describes the default colors in the color palette.
0 Black 8 Gray
1 Blue 9 Light Blue
2 Green 10 Light Green
3 Cyan 11 Light Cyan
4 Red 12 Light Red
5 Magenta 13 Light Magenta
6 Brown 14 Yellow
7 Off White 15 White
The value of the <foreground> parameter for the text mode must be in
the range 0 to 31. Adding 16 to the color values causes characters to
blink.
You can specify a maximum of two different colors for text mode.
EXAMPLE:
The statement:
10COLOR 0,10,10
PURPOSE:
Selects one of 15 colors from the palette as the background color and
, one of two color groups as the foreground colors. See the PALETTE
statement later in this section for a discussion of the colors in the palette.
SYNTAX:
COLOR [<background> H,[ <color group>]]
Table 6-2 describes the default colors for each color group associated
with the color values you select in graphic output statements such as
CIRCLE, LINE; and DRAW.
1 Green Cyan
2 Red Magenta
3 Brown White
NOTES:
The value for the <background> parameter may range from 0 to 15.
This value specifies an index into the palette to obtain the background
color. The background color is also the color produced by using a color
value of 0 in graphics statements. If the <background> parameter is
omitted, the COLOR statement assumes the previous value for the
background color.
°
The value of the <color group> parameter is either even or odd. Even
values for this parameter select color group and odd values select
color group 1.
°
The number of colors available depends on the current screen mode.
Modes 2,3, and 7 can use only colors and 1 from the selected
graphics palette. Modes 1, 5, and 6 can use colors 0, 1,2, and 3. Mode
4 can specify any of the 16 colors from the palette.
EXAMPLE:
The program:
10 SCREEN 5
20 COLOR 10,1
places the system in screen mode 5 for 640 by 200 resolution, selects
light green for the background and selects palette 1 so that color values
0,1,2, and 3 represent light green, cyan, magenta, and white,
respectively.
Commands, Statements, Functions, and Variables 6-41
COM STATEMENT
PURPOSE:
Enables or disables event trapping of communications activity on the
specified channel.
SYNTAX:
COM(n) ON
COM(n) OFF
COM(n) STOP
(n) is the number of the communications channel. The range for (n)
is 1 to 3.
NOTES:
The COM(n) ON statement enables communications event trapping by
an ON COM statement (see "ON COM Statement" later in this section).
While trapping is enabled, if a non-zero line number is specified in the
ON COM statement, GW-BASIC checks between every statement to see
if activity has occurred on the communications channel. If it has, the ON
COM statement is executed.
EXAMPLE:
10 COM(1) ON
COMMON STATEMENT
PURPOSE:
Passes variables to a CHAINed program.
SYNTAX:
COMMON <list of variables>
NOTES:
The COMMON statement is used in conjunction with the CHAIN
statement. COMMON statements may appear anywhere in a program,
though they should normally appear at the beginning.
The same variable cannot appear in more than one COMMON state-
ment. Array variables are specified by appending "0" to the variable
name. If all variables are to be passed, use CHAIN with the ALL option
and omit the COMMON statement.
COMMON AO
COMMON A(3)
EXAMPLE:
100 COMMON A,B,C,DO,G$
110 CHAIN "PROG3",10
Commands, Statements, Functions, and Variables 6-43
CONT COMMAND
PURPOSE:
Continues program execution after a CTRL-C has been typed or a STOP
or END statement has been executed.
SYNTAX:
CO NT
NOTES:
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 prompt ("7" or prompt string).
CONT is invalid if the program has been edited during the break.
EXAMPLE:
See "STOP Statement" later in this section.
6-44 GW-BASIC Reference Manual
COS FUNCTION
PURPOSE:
Returns the cosine of X, where X is in radians.
SYNTAX:
y = COS(X)
NOTES:
The calculation of COS(X) is performed in single precision.
EXAMPLE:
The function:
10 X= 2*COS(.4)
20 PRINTX
will yield:
1.842122
Commands, Statements, Functions, and Variables 6-45
CSNG FUNCTION
PURPOSE:
Converts X to a single precision floating-point number.
SYNTAX:
Y = CSNG(X)
NOTES:
See the CINT and CDBL functions earlier in this section for information
about converting numbers to the integer and double precision data
types, respectively.
EXAMPLE:
The function:
10 A# = 975.3421#
20 PRINT A#; CSNG(A#)
will yield:
975.3421 975.3421
GW-BASIC Reference Manual
PURPOSE:
Stores the current line position of the cursor in a numeric variable.
NOTES:
To return the current column position of the cursor, use the POS function.
EXAMPLE:
10 Y = CSRLlN 'Record current line.
20 X = POS(O) 'Record current column.
30 LOCATE 24,1 :PRINT "HELLO"
'Print HELLO on last line.
40 LOCATE Y, X 'Restore position to old line and column.
Commands, Statements, Functions, and Variables 6-47
SYNTAX:
Y = CVI«2-byte string»
Y = CVS«4-byte string»
Y = CVD( <8-byte string»
NOTES:
Numeric values that are read in from a random disk file must be
converted from strings back into numbers. CVI converts a 2-byte string
to an integer. CVS converts a 4-byte string to a single precision number.
CVD converts an 8-byte string to a double precision number.
See also "MKI$, MKS$, and MKD$ Functions" later in this section.
EXAMPLE:
DATA STATEMENT
PURPOSE:
Stores the numeric and string constants that are accessed by the
program's READ statement(s).
SYNTAX:
DATA <list of constants>
NOTES:
DATA statements are nonexecutable and may be placed anywhere in the
program. A DATA statement may contain as many constants (separated
by commas) as will fit on a logical line. Any number of DATA statements
may be used in a program.
The variable type (numeric or string) given in the READ statement must
agree with the corresponding constant in the DATA statement.
EXAMPLE:
See "READ Statement" later in this section.
Commands, Statements, Functions, and Variables 6-49
DATE$ STATEMENT
PURPOSE:
Sets the current date. This statement complements the DATE$ variable,
which retrieves the current date.
SYNTAX:
DATE$ = <string expression>
mm-dd-yy
mm-dd-yyyy
mm/dd/yy
mm/dd/yyyy
EXAMPLE:
10 DATE$ = "11-08-1983"
DATE$ VARIABLE
PURPOSE:
Retrieves the current date. (To set the date, use the DATE$ statement,
described previously.)
NOTES:
The DATE$ variable contains a ten-character string in the form mm-dd-
yyyy, where mm is the month (01 through 12), dd is the day (01 through
31), and yyyy is the year (1980 through 2099).
EXAMPLE:
10 PRINT DATE$
This statement prints the date, calculated from the date set with the
DATE$ statement.
Commands, Statements, Functions, and Variables 6-51
DEF FN STATEMENT
PURPOSE:
Defines and names a function written by the user.
SYNTAX:
DEF FN<name>[( <parameter list»] = <function definition>
NOTES:
<name> must be a legal variable name. This name, preceded by FN,
becomes the name of the function.
EXAMPLE:
Line 410 defines the function FNAB. The function is called in line 420.
6-52 GW-BASIC Reference Manual
DEFINT/SNG/DBUSTR STATEMENTS
PURPOSE:
Declares variable types as integer, single precision, double precision, or
string.
SYNTAX:
DEF<type> <range(s) of letters>
NOTES:
Any variable names beginning with the letter(s) specified in <range(s)
of letters> will be considered the type of variable specified in the
<type> portion of the statement. However, a type declaration character
always takes precedence over a DEFtype statement. (See "Variable
Names and Declaration Characters" in Section 2.)
EXAMPLES:
In the statement:
10 DEFDBl l-P
10 DEFSTR A
all variables beginning with the letter A will be string variables. In the
statement:
10 DEFINT I-N,W-Z
PURPOSE:
Defines an animation object as a group of arrays where each array
contains a view of the object. The sequence of the arrays determines
the order in which the views of that object appear.
SYNTAX:
DEF OBJECT <object number>[AS<array 1>[,<array 2> ... ]]
<object number> specifies the number for the object being defined.
<array 1>, <array 2> ... contain successive views of the object being
defined.
NOTES:
Up to 8 views can be specified for an object. GW-BASIC displays the
views in the order of their definition.
The DEF OBJECT statement sets all attributes for the specified object to
their default values (see the description of the OBJECT statement later in
this section). This statement returns an error if the specified object is
already defined. An object can be undefined by using the DEF OBJECT
statement without including any array names.
EXAMPLES:
The statement:
defines the MAN1, MAN2, and MAN3 arrays as the different views of
object 3. The statement also sets up an array to preserve the screen
image overlaid by object 3. The statement:
10 DEF OBJECT 3
PURPOSE:
Assigns the current segment address that will be referenced by a
subsequent BLOAO, BSAVE, CALL, CALLS, or POKE statement or by a
USR or PEEK function.
SYNTAX:
OEF SEG [ = <address>]
NOTES:
The address specified is saved for use as the segment required by
BLOAO, BSAVE, CALL, CALLS, POKE, USR, and PEEK.
Entry of any value outside the <address> range a through 65535 will
result in an "Illegal function call" error, and the previous value will be
retained. -
EXAMPLE:
10 OEF SEG = &HB800 'Set segment to B800 Hex
20 OEF SEG 'Restore segment to GW-BASIC data segment
Commands, Statements, Functions, and Variables 6-55
PURPOSE:
Specifies the starting address of an assembly language subroutine.
SYNTAX:
DEF USR[ <digit> 1= <integer expression>
NOTES:
<digit> may be any digit from 0 to 9. The digit corresponds to the
number of the USR routine whose address is being specified. If <digit>
is omitted, DEF USRO is assumed.
EXAMPLE:
DELETE COMMAND
PURPOSE:
Deletes program lines.
SYNTAX: (
DELETE [ <line number> ][ - <line number> ]
NOTES:
GW-BASIC always returns to the command level after a DELETE is
executed. If <line number> does not exist, an "Illegal function call"
error occurs.
EXAMPLES:
The command:
DELETE 40
DELETE 40 -100
DELETE -40
DELETE 40-
PURPOSE:
Dimensions an array large enough to contain the display data for a
graphic object.
SYNTAX:
DIM OBJECT <array name>«x size>,<y size»
<array name> is the name of the numeric array to contain the display
data for the object. <x size> and <y size> are the horizontal and
vertical object dimensions, respectively. The object dimensions are
specified in logical units defined by the current window.
NOTES:
The DIM OBJECT statement produces a single-dimensioned array to
contain a view of an object of the specified size based on the screen
mode at the time the statement was executed.
EXAMPLE:
The statement:
DIM STATEMENT
PURPOSE:
Specifies the maximum values for array variable subscripts and allo-
cates storage accordingly.
SYNTAX:
DIM <list of subscripted variables>
NOTES:
If an array variable name is used without a 01 M statement, the maximum
value of the array's subscript(s) is assumed to be 10. If a subscript
greater than the specified maximum is used, a "Subscript out of range"
error occurs. The minimum value for a subscript is always 0, unless
otherwise specified with the OPTION BASE statement (described later
in this section).
The DIM statement sets all the elements of the specified arrays to an
initial value of zero.
EXAMPLE:
10 DIM A(20)
20 FOR I = 0 TO 20
30 READ A(I)
40 NEXT I
Commands, Statements, Functions, and Variables 6-59
DRAW STATEMENT
PURPOSE:
Draws a line as indicated by the subcommands described below.
SYNTAX:
DRAW <string expression>
NOTES:
The DRAW statement contains 17 subcommands. These subcommands
combine many of the capabilities of the other GW-BASIC graphics
statements into an "object definition language" called Graphics Macro
Language (GML). An object definition language is a language that
defines a complete set of characteristics of a particular object. In this
case, the characteristics are motion (up, down, left, right), color, angle,
and scale factor.
Command Explanation
The following prefix commands may precede any of the above move-
ment commands:
Command Explanation
EXAMPLES:
10 U$ = "U30;" : D$ = "D30;" : L$ = "L40;" R$ = "R40;"
20 BOX$ = U$ + R$ + D$ + L$
30 DRAW "XBOX$;"
40 REM DRAW "XU$;XR$;XD$;XL$;" would have drawn the same box
EDIT COMMAND
PURPOSE:
Enters edit mode at the specified line.
SYNTAX:
EDIT <line number>
NOTES:
In edit mode, it is possible to edit portions of a line without retyping the
entire line. Upon entering edit mode, GW-BASIC types the number of
the line to be edited and waits for you to use the editor to make any
necessary changes.
Commands; Statements, Functions, and Variables 6-63
END STATEMENT
PURPOSE:
Terminates program execution, closes all files, and returns to command
level.
SYNTAX:
END
NOTES:
END statements may be placed anywhere in the program to terminate
execution. An END statement at the end of a program is optional.
GW-BASIC always returns to command level after an END is executed.
Unlike the STOP statement, END does not cause a "Break in line nnnnn"
message to be printed.
EXAMPLE:
520 IF K>1000 THEN END ELSE GOTO 20
6-64 GW-BASIC Reference Manual
ENVIRON STATEMENT
PURPOSE:
Modifies parameters in BASIC's environment string table. Parameter
modification may be to change the "PATH" parameter for a Child
process (see the "ENVIRON$" function and the "SHELL" statement in
this section; also see "The MS-DOS 2.0 Utilities - PATH command" in the
Mindset MS-DOS Manual). This statement can also be used to pass
parameters to a Child process by inventing a new environment
parameter.
SYNTAX:
ENVIRON <parm>
NOTES:
The following rules apply to the ENVIRON statement:
EXAMPLES:
Unless changed by the MS-DOS command PATH, the BASIC environ-
ment string table is empty. The following statement will create a default
"PATH" to the root directory on Disk A:
PATH =A:\
Commands, Statements, Functions, and Variables 6-65
ENVIRON CAT =;
PATH =A:\SALES;A:\ACCOUNTING;B:\DOG
6-66 GW-BASICReference Manual
ENVIRON$ FUNCTION
PURPOSE:
Retrieves the specified environment string from BASIC's environment
string table.
SYNTAX:
X$ = ENVIRON$ «parm»
or:
NOTES:
The following rules apply to the ENVIRON$ function:
EXAMPLES:
Unless changed by the DOS command PATH, the initial BASIC environ-
ment string is empty (see "The ENVIRON Statement" earlier in this
section). The ENVIRON statement example would cause the environ-
ment string table to contain:
PATH = A:\SALES;A:\ACCOUNTING;B:\DOG
Commands, Statements, Functions, and Variables 6-67
PRINT ENVIRON$("PATH")
A:\SALES;A:\ACCOUNTING;B:\DOG
PRINT ENVIRON$(1)
PATH =A:\SALES;A:\ACCOUNTING;B:\DOG
EOF FUNCTION
PURPOSE:
Tests for the end-of-file condition.
SYNTAX:
X = EOF( <file number»
NOTES:
Returns -1 (true) if the end of a sequential file has been reached. To
avoid "Input past end" errors, use EOF to test for end-of-file while
inputting.
EXAMPLE:
10 OPEN "1",1, "DATA"
20 C=O
30 IF EOF(1) THEN 100
40INPUT#1,M(C)
50 C=C+1:GOTO 30
Commands, Statements, Functions, and Variables 6-69
ERASE STATEMENT
PURPOSE:
Eliminates arrays from memory.
SYNTAX:
ERASE <list of array variables>
NOTES:
After an array is erased, either a new DIM statement must be used to
re-create the array, or the previously allocated array space in memory
may be used for other purposes. If an attempt is made to revise the
dimension of an array without first erasing it, a "Duplicate definition"
error occurs.
Make sure that you do not erase any arrays which are part of a current
DEF OBJECT statement.
EXAMPLE:
PURPOSE:
When a device error routine is entered, the variable ERDEV contains the
error code of the device error. Similarly, if the device causing the error is
a character device, the variable ERDEV$ contains the name of the
device.
The handler for interrupt X'24' sets ERDEV (and ERDEV$ if the device
causing the error is a character device).
ERDEV will contain the INT 24 error code in the lower 8 bits, and the
upper 8 bits will contain the "word attribute bits" (b15-b13) from the
device header block.
If the error was on a character device, ERDEV$ will contain the 8-byte
character device name. If the error was not on a character device,
ERDEV$ will contain the two-character block device name (A:, B:, C:,
etc.).
NOTES:
These variables are read-only variables which you cannot alter with a
BASIC assignment statement.
EXAMPLE:
User-installed device driver "MYLPT2" caused a "Printer out of Paper"
error via INT 24.
ERDEV contains the error number 9 in the lower 8 bits and the device
header word attributes in the upper 8 bits.
PURPOSE:
When an error-handling routine is entered, the variable ERR contains the
error code for the error, and the variable ERL contains the line number of
the line in which the error was detected. The ERR and ERL variables are
usually used in IF. .. THEN statements to direct program flow in the error-
handling routine.
If the statement that caused the error was a direct mode statement, ERL
will contain 65535. To test whether an error occurred in a direct
statement, use IF 65535 = ERL THEN .... Otherwise, use:
If the line number is not on the right side of the relational operator, it
cannot be renumbered with RENUM. Because ERL and ERR are
reserved variables, neither may appear to the left of the equal sign in a
LET (assignment) statement. GW-BASIC error codes are listed in
Appendix A, "Error Codes and Error Messages".
NOTES:
These variables are read-only variables that you cannot alter with a
BASIC assignment statement.
\
6-72 GW-BASIC Reference Manual
ERROR STATEMENT
PURPOSE:
Simulates the occurrence of a BASIC error, or enables the user to define
error codes.
SYNTAX:
ERROR <integer expression>
NOTES:
ERROR can be used as a statement (part of a program source line) or as
a command (in direct mode).
The value of <integer expression> must be greater than 0 and less than
255. If the value of <integer expression> equals an error code already
in use by BASIC (see Appendix A), the ERROR statement will simulate
the occurrence of that error and the corresponding error message will be
printed. (See Example 1.)
To define your own error code, use a value that is greater than any used
by GW-BASIC error codes. (It is preferable to use the highest available
values, so compatibility may be maintained when more error codes are
added to GW-BASIC.) This user-defined error code may then be
conveniently handled in an error-handling routine. (See Example 2.)
EXAMPLES:
The following example:
10 S=10
20T=5
30 ERROR S+ T
40END
will yield:
Ok
ERROR 15
String too long
Ok
Commands, Statements, Functions, and Variables 6-73
EXP FUNCTION
PURPOSE:
Returns e (base of natural logarithms) to the power of X. X must be
< = 88.02969.
SYNTAX:
Y = EXP(X)
NOTES:
If X is greater than 88.02969, the "Overflow" error message is displayed,
machine infinity with the appropriate sign is supplied as the result, and
execution continues.
EXAMPLE:
The function:
10X=5
20 PRINT EXP(X-1)
will yield:
54.59815
Commands, Statements, Functions, and Variables 6-75
FIELD STATEMENT
PURPOSE:
Allocates space for variables in a random file buffer.
SYNTAX:
FIELD [#]<file number>,<field width> AS <string variable> ...
NOTES:
Before a GET statement or a PUT statement can be executed, a FIELD
statement must be executed to format the random file buffer.
<file number> is the number under which the file was opened.
<field width> is the number of characters to be allocated to
<string variable>.
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.
EXAMPLES:
In Example 1, the statement:
allocates the first 20 positions (bytes) in the random file buffer to the
string variable N$, the next 10 positions to 10$, and the next 40 positions
to ADD$. FIELD does not place any data in the random file buffer. (See
also the descriptions of the GET, LSET, and RSET statements, elsewhere
in this section.)
10 OPEN "R",#1,':A:PHONELST",35
15 FIELD #1,2 AS RECNBR$,33 AS DUMMY$
20 FIELD #1,25 AS NAME$,10 AS PHONENBR$
25 GET #1
30 TOTAL = CVI(RECNBR$)
35 FOR I = 2 TO TOTAL
40 GET #1, I
45 PRINT NAME$, PHONENBR$
50 NEXT I
10 FOR LOOP% = 0 TO 7
20 FIELD #1,(LOOP%*16) AS OFFSET$,16 AS
A$(LOOP%)
30 NEXT LOOP%
FILES STATEMENT
PURPOSE:
Prints the names of files residing on the specified disk or RAM
cartridge.
SYNTAX:
FILES [<filespec>]
NOTES:
If <filespec> is omitted, all the files on the currently selected drive will
be listed. <filespec> is a string formula which may contain question
marks (?) or asterisks (*) used as wild cards. A question mark will
match any single character in the filename or extension. An asterisk
will match one or more characters starting at that position. The
asterisk is a shorthand notation for a series of question marks.
If you start GW-BASIC directly from the cartridge, rather than from
MS-DOS, the FILES statement operates only with RAM cartridge
directories and pathnames are not valid.
EXAMPLES:
FILES
FILES "*.BAS"
FILES "TEST?BAS"
shows all five-letter files whose names start with "TEST" and end with
the .BAS extension.
FILES "CART1:*.*"
FILES ',\SALES"
FILES "\SALES\MARY\"
FIX FUNCTION
PURPOSE:
Returns the truncated integer part of X.
SYNTAX:
Y = FIX(X)
NOTES:
FIX(X) is equivalent to SGN(X)* INT(ABS(X)). The difference between
FIX and INT is that FIX does not return the next lower number for
negative X.
EXAMPLES:
The function:
PRINT FIX(58.75)
will yield:
58
The function:
will yield:
-58
Comrr.ands, Statements, Functions, and Variables 6-81
PURPOSE:
Enables a series of instructions to be performed in a loop a given
number of times.
SYNTAX:
FOR <variable> = X TO Y [STEP Z]
NOTES:
<variable> is used as a counter. The first numeric expression (X) is the
initial value of the counter. The second numeric expression (Y) is the
final value of the counter.
The program lines following the FOR statement are executed until the
NEXT statement is encountered. Then the counter is adjusted by the
amount (Z) specified by STEP. A check is performed to see if the value
of the counter is now greater than the final value (Y). If it is not greater,
GW-BASIC loops back to the statement after the FOR statement and the
process is repeated. If the value of the counter is greater, execution
continues with the statement following the NEXT statement.
The body of the loop is skipped if the initial value of the loop times the
sign of the STEP exceeds the final value times the sign of the STEP.
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
nested, each loop must have a unique variable name as its counter. The
NEXT statement for the inside loop must appear before the NEXT
statement for the outside loop. If nested loops have the same end point,
a single NEXT statement may be used for all of them.
The variable(s) in the NEXT statement may be omitted, in which case the
NEXT statement will match the most recent FOR statement. If a NEXT
statement is encountered before its corresponding FOR statement, a
"NEXT without FOR" error message is issued and execution is
terminated.
EXAMPLES:
In Example 1:
10 K=10
20 FOR I = 1 TO K STEP 2
30 PRINT I;
40 K=K+10
50 PRINT K
60 NEXT
will yield:
120
330
540
750
960
In Example 2:
10 J=O
20 FOR I = 1 TO J
30 PRINT I
40 NEXT I
the loop does not execute because the initial value of the loop exceeds
the final value.
Commands, Statements, Functions, and Variables 6-83
In Example 3:
101=5
20 FOR I = 1 TO I + 5
30 PRINT I;
40 NEXT
will yield:
12345678910
The loop executes ten times. The final value for the loop variable is
always set before the initial value is set.
6-84 GW-BASIC Reference Manual
FRE FUNCTION
PURPOSE:
Returns the number of free bytes. With a numeric argument, FRE returns
the number of bytes in memory that are not being used by GW-BASIC.
Arguments to FRE are dummy arguments.
SYNTAX:
X = FRE(O)
X = FRE("")
NOTES:
FRE('''') forces a garbage collection before returning the number of free
bytes. Garbage collection may take as long as 1 to 1-112 minutes.
GW-BASIC does not initiate garbage collection until all free memory has
been used up. Therefore, using FRE("") periodically results in shorter
delays for each garbage collection.
EXAMPLE:
PRINT FRE(O)
PURPOSE:
Reads a record from a random disk file into a random buffer.
SYNTAX:
GET [#]<file number>[,<record number>]
NOTES:
<file number> is the number under which the file was OPENed. If
<record number> is omitted, the next record (after the last GET) is read
into the buffer. 'The largest possible record number is 16,777,215. The
smallest possible record number is 1.
The GET and PUT statements allow fixed-length input and output for
GW-BASIC communications (COM) files. However, because of the low
performance associated with telephone line communications, GET and
PUT statements are not recommended for telephone communication.
After a GET statement has been executed, INPUT# and LINE INPUT #
may be executed to read characters from the random file buffer.
EXAMPLE:
GET #1,75
will place record number 75 from the file OPENed as #1 into the random
buffer.
6-86 GW-BASIC Reference Manual
PURPOSE:
Used with the PUT statement to transfer graphic images (objects) to and
from the screen and to retrieve graphic images for animation.
SYNTAX:
GET (X1, Y1) - (X2, Y2), <array name>
(X1 ,Y1) - (X2,Y2) is a rectangle which contains the object on the display
screen. The rectangle is defined the same way as the rectangle drawn
by the LINE statement using the ,B option.
<array name> is the name assigned to the array that will hold the
image. The array can be any type except a string array. The array
dimension must be large enough to hold the entire image. Unless the
array is type integer, however, the contents of the array after a GET will
be meaningless when interpreted directly.
NOTES:
The GET statement transfers the screen image bounded by the
rectangle described by the specified points into the array. Later, a
corresponding PUT statement can transfer the image stored in the array
back onto the screen. Additionally, these objects can be used for
animation.
The actual value used in the DIM statement for an array depends on the
type of the array. Integer arrays hold 1 word per element, single
precision arrays hold 2 words per element, and double precision arrays
hold 4 words per element.
Commands, Statements, Functions, and Variables 6-87
EXAMPLE:
10 DIM FIGURE1 (44)
20 GET (10,10) - (30,30), FIGURE1
PURPOSE:
Branches to and returns from a subroutine.
SYNTAX:
GOSUB <line number>
NOTES:
<line number> in the GOSUB statement is the first line of the
subroutine.
EXAMPLE:
The statements:
10 GOSUB 40
20 PRINT "BACK FROM SUBROUTINE"
30END
40 PRINT "SUBROUTINE";
50 PRINT" IN";
60 PRINT" PROGRESS"
70 RETURN
Commands, Statements, Functions, and Variables 6-89
will yield:
SUBROUTINE IN PROGRESS
BACK FROM SUBROUTINE
6-90 GW-BASIC Reference Manual
GOTO STATEMENT
PURPOSE:
Branches unconditionally out of the normal program sequence to a
specified line number.
SYNTAX:
GOTO <line number>
NOTES:
If <line number> is an executable statement, that statement and those
following are executed. If <line number> is a nonexecutable statement,
execution proceeds at the first executable statement encountered after
<line number>.
EXAMPLE:
10 READ R
20 PRINT "R = ";R,
30 A=3.14*R/\2
40 PRINT 'f\REA = ";A
50 GOTO 10
60 DATA 5,7,12
will yield:
HEX$ FUNCTION
PURPOSE:
Returns a string that represents the hexadecimal value of the decimal
argument.
SYNTAX:
Y$ = HEX$(X)
NOTES:
X is rounded to an integer before HEX$(X) is evaluated.
EXAMPLE:
The function:
10 INPUT X
20 A$ = HEX$(X)
30 PRINT X "DECIMAL IS "A$" HEXADECIMAL"
will yield:
? 32
32 DECIMAL IS 20 HEXADECIMAL
For details on octal conversion, see the OCT$ function, later in this
section.
6-92 GW-BASIC Reference Manual
PURPOSE:
Makes a decision regarding program flow based on the result returned
by an expression.
SYNTAX 1:
IF <expression> THEN { <statement(s»I<line number>}
[ELSE {<statement(s»I<line number>}]
SYNTAX 2:
IF <expression> GOTO <line number>
[ELSE { <statement(s»I<line number>}]
NOTES:
If the result of <expression> is not zero, the THEN or GOTO clause is
executed. THEN may be followed by either a line number for branching
or one or more statements to be executed. GOTO is always followed by
a line number.
Nested IF Statements
IF. .. THEN ... ELSE statements may be nested. Nesting is limited only by
the length of the line. For example:
is a legal statement. If the statement does not contain the same number
of ELSE and THEN clauses, each ELSE is matched with the closest
unmatched THEN. For example:
Floating-Point Computations
When using IF to test equality for a value that is the result of a floating-
point computation, remember that the internal representation of the
value may not be exact. Therefore, the test should be against the range
over which the accuracy of the value may vary. For example, to test a
computed variable A against the value 1.0, use:
This test returns true if the value of A is 1.0 with a relative error of less than
1.0E-6.
EXAMPLES:
In Example 1:
this statement GETs record number I from file number 1 if I is not zero.
In Example 2:
a test determines if I is greater than 10 and less than 20. If I is within this
range, DB is calculated and execution branches to line 300. If I is not
within this range, execution continues with line 110.
In Example 3:
this statement causes printed output to go either to the screen or the line
printer, depending on the value of the variable 10FLAG. If 10FLAG is
zero, output goes to the line printer; otherwise, output goes to the
screen.
6-94 GW-BASIC Reference Manual
INKEY$ FUNCTION
PURPOSE:
Returns a string containing a character read from the keyboard.
SYNTAX:
X$ = INKEY$
NOTES:
The INKEY$ function does not echo characters to the screen. All
characters are passed through to the program except for the BREAK
key, CTRL-BREAK, and CTRL-C, which terminate the program.
The INKEY$ function returns the next [email protected] the keyboard buffer.
The string returned by INKEY$ is 0,1, or 2 characters long. A null string
is returned if there are no characters waiting to be read from the
keyboard buffer.
INKEY$ returns a string containing a single character for keys with ASCII
character codes (see Appendix C for a list of the ASCII character
codes). A two-character string is returned for keys with extended codes.
The first character is code 000, and the second character is the
extended code for that key. (See Appendix C for a list of extended
character codes.)
EXAMPLE:
This routine uses a FOR-NEXT loop to limit the amount of time allowed to
answer a prompt:
INP FUNCTION
PURPOSE:
Returns the byte read from port I. I must be in the range 0 to 65535.
SYNTAX:
X = INP(I)
NOTES:
INP is the complementary function to the OUT statement.
EXAMPLE:
100 A= INP(54321)
MOV DX,54321
IN AL,DX
6-96 GW-BASIC Reference Manual
INPUT STATEMENT
PURPOSE:
Allows input from the keyboard during program execution.
SYNTAX:
INPUT[;] [<"prompt string">{;I,}]<list of variables>
NOTES:
When an INPUT statement is encountered, program execution pauses
and a question mark is printed to indicate that the program is waiting for
data. If <"prompt string"> is included, the string is printed before the
question mark. The required data is then entered at the keyboard.
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 (numeric instead of string, and so on) causes the message
"?Redo from start" to be printed. No assignment of input values is made
until an acceptable response is given.
EXAMPLES:
The statement:
10lNPUTX
20 PRINTX "SQUARED IS" X!\2
30 END
will yield:
The statement:
10PI=3.14
20 INPUT "WHAT IS THE RADIUS";R
30A=PI*R/\2
40 PRINT "THE AREA OF THE CIRCLE IS";A
50 PRINT
60 GOTO 20
will yield:
INPUT# STATEMENT
PURPOSE:
Reads data items from a sequential device or file and assigns them to
program variables.
SYNTAX:
INPUT#<file number>,<variable list>
NOTES:
<file number> is the number used when the file was OPENed for input.
<variable list> contains the variable names that will be assigned to the
items in the file. (The variable type must match the type specified by the
variable name.) With INPUT#, no question mark is printed, as with
INPUT.
The data items in the file should appear just as they would if data were
being typed in response to an INPUT statement. With numeric values,
GW-BASIC ignores leading spaces, carriage returns, and linefeeds. The
first character encountered that is not a space, carriage return, or
linefeed is assumed to be the start of a number. The number terminates
on a space, carriage return, linefeed, or comma.
If GW-BASIC is scanning the sequential data file for a string item, it will
also ignore leading spaces, carriage returns, and linefeeds. The first
character encountered that is not a space, carriage return, or linefeed is
assumed to be the start of a string item.
If this first character is a quotation mark ("), the string item will consist of
all characters read between the first quotation mark and the second.
Thus, a quoted string may not contain a quotation mark as a character.
If the first character of the string is not a quotation mark, the string is an
unquoted string, and will terminate on a comma, carriage return, or
linefeed (or after 255 characters have been read).
EXAMPLE:
INPUT#2,A,B,C
Commands, Statements, Functions, and Variables 6-99
INPUT$ FUNCTION
PURPOSE:
Returns a string of I characters, read from file number J. If the file
number is not specified, the characters will be read from the screen.
SYNTAX:
X$ = INPUT$(I[,[#]J])
NOTES:
If the keyboard is used for input, no characters will be echoed on the
screen. All control characters are passed through except CTRL-C,
which is used to interrupt the execution of the I NPUT$ function.
EXAMPLES:
Example 1:
Example 2:
INSTR FUNCTION
PURPOSE:
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.
SYNTAX:
J = INSTR([I,]X$,Y$)
NOTES:
I must be in the range 1 to 255. If I is greater than the number of
characters in X$ (LEI\i(X$)), or if X$ is null or Y$ cannot be found, INSTR
returns O. If Y$ is null, INSTR returns I or 1. X$ and Y$ may be string
variables, string expressions, or string literals.
EXAMPLE:
The function:
10 X$ = ':A.8CDE8"
20 Y$= "8"
30 PRINT INSTR(X$,Y$);INSTR(4,X$,Y$)
will yield:
26
Commands, Statements, Functions, and Variables 6-101
INT FUNCTION
PURPOSE:
Returns the largest integer < = X.
SYNTAX:
Y = INT(X)
EXAMPLES:
The function:
PRINT INT(99.89)
will yield:
99
The function:
will yield:
-13
See the CINT and FIX functions, earlier in this section, which also return
integer values.
6-102 GW-BASIC Reference Manual
IOCTL STATEMENT
PURPOSE:
Enables a BASIC program to send a control data string to a user-
supplied character device driver any time after the driver has been
OPENed.
SYNTAX:
IOCTL [#]<file number>, <string>
NOTES:
IOCTL commands are generally 2 to 3 characters, optionally followed
by an alphanumeric argument. An IOCTL command string may be up
to 255 bytes long, with commands within the string separated by
semicolons (';'). An example of an IOCTL command string is:
"OO;SW132;GW" .
EXAMPLES:
If a user had installed a device driver to replace LPT1, and that driver
was able to set page length (the number of lines to print on a page
before issuing a form feed character), then an IOCTL command to set or
change the page length might have the form:
PLn
An IOCTL statement to open the new LPT1 driver and set the page
length would then be:
This statement opens LPT1 with an initial page length of 66 lines. The
statement:
would also open LPT1, but with an initial page length of 56 lines.
IOCTL$ FUNCTION
PURPOSE:
Enables a BASIC program to read a control data string from a character
device driver that is OPEN.
SYNTAX:
X$ = IOCTL$([#]<file number»
NOTES:
The IOCTL$ function is generally used to get acknowledgement that an
IOCTL statement succeeded or failed. It is also used to get device
information after an IOCTL command is issued using the IOCTL
statement.
EXAMPLE:
OPEN ',\OEV\FOO" AS #1
IOCTL #1, "RAW" 'Tell device that data is "raw"
IF IOCTL$(1) = "0" THEN CLOSE 1
In this example, if character driver 'FOO' returns false from the raw data
mode IOCTL request, the program closes the file because raw data is
required by the program. This example assumes that a device driver
FOO, programmed to accept the required control strings, has been
installed.
6-104 GW-BASIC Reference Manual
KEY STATEMENT
PURPQSE:
Assigns softkey values to function keys and display the values.
SYNTAX:
KEY n,X$
KEY n,CHR$«shift> )+CHR$«scan code»
KEY LIST
KEY ON
KEY OFF
n Key n Key
1 F1 11 Cursor up
2 F2 12 Cursor left
3 F3 13 Cursor right
4 F4 14 Cursor down
5 F5 15 User-defined
6 F6 16 User-defined
7 F7 17 User-defined
8 F8 18 User-defined
9 F9 19 User-defined
10 F10 20 User-defined
NOTES:
The KEY statement allows function keys to be designated for special
"softkey" functions. Each of the ten function keys may be assigned a
15-byte string which, when that key is pressed, will be input to
GW-BASIC.
Initially, the soft keys are assigned the following values (the names of
keys are boxed):
KEY OFF erases the soft key display from the twenty-fifth line, making
that line available for program use. It does hot disable the function keys.
KEY LIST displays all ten soft key values on the screen,with all 15
characters of each key displayed.
If the function key number is not in the range 1-20, an "Illegal function
call" error is produced, and the previous key string expression is
retained.
When a soft key is assigned, the INKEY$ function returns one character
of the softkey string per invocation.
1. The line printer echo key is processed first. Defining the Print Screen
key as a user-defined key trap will not prevent characters from being
echoed to the line printer if depressed.
2. Function keys and the cursor direction keys are examined next.
Defining a function key or cursor direction key as a user-defined key
trap will have no effect, because they are considered pre-defined.
4. Any key that is trapped is not passed on. That is, the key is not read
by GW-BASIC.
EXAMPLES:
50 KEY ON 'Displays the softkey on 25th line
60 KEY OFF' Erases softkey display
70 KEY 1, "MENU" + CHR$(13) , Assigns the string
"MENU" followed by a carriage return to softkey 1.
80 KEY 1, "" 'Disables soft key 1
KEY(n) STATEMENT
PURPOSE:
Enables or disables event trapping of softkey or cursor direction key
activity for the specified function key.
SYNTAX:
KEY(n) ON
KEY(n) OFF
KEY(n) STOP
(n) is the number of a function key or cursor direction key. (See "KEY
Statement" for information on assigning softkey values to function
keys.) The cursor direction keys are numbered sequentially after the
function keys in the following order: up, left, right, down.
NOTES:
Note that the KEY statement assigns softkey and cursor direction values
to function keys and displays the values. Do not confuse KEY ON and
KEY OFF, which display and erase these values, with the event-trapping
statements described here.
KEY(n) OFF disables the event trap. If an event takes place, it is not
remembered.
EXAMPLE:
10 KEY 4, "SCREEN 0,0" , assigns softkey 4
20 KEY(4) ON 'enables event trapping
(key 4 pressed)
KILL STATEMENT
PURPOSE:
Deletes a file from disk or a RAM cartridge.
SYNTAX:
KILL <filespec>
NOTES:
KILL is used for all types of disk files: program files, random data files,
and sequential data files. The filespec may contain question marks (?)
or asterisks (*) used as wild cards. A question mark will match any
single character in the filename or extension. An asterisk will match one
or more characters starting at the position of the asterisk.
KILL also allows a path name in place of <filespec>. KILL checks to see
if the file is open; and, if so, will give a "File already open" error.
KILL, like OPEN, cannot distinguish a file in another directory from a file
you may have open. It is possible to get an unexpected "File already
open" error under these circumstances. (See "OPEN Statement" later in
this section.)
KILL can delete disk files only if GW-BASIC was started from MS-DOS.
Otherwise KILL can delete only BASIC files contained on RAM
cartridges.
EXAMPLES:
200 KILL "DATA1?.DAT"
Deletes all files whose six-letter names begin with DATA1 and have the
extension ,OAT.
The position taken by the question mark can contain any valid filename
character.
deletes the file ABC.123 from the RAM cartridge in cartridge port 2.
Commands, Statements, Functions, and Variables 6-111
LEFT$ FUNCTION
PURPOSE:
Returns a string comprising the leftmost I characters of X$.
SYNTAX:
Y$ = LEFT$(X$,I)
NOTES:
I must be in the range a to 255. If I is greater than the number of
characters in X$ (LEN(X$)), the entire string (X$) will be returned.
If I = 0, the null string (length zero) is returned.
EXAMPLE:
The function:
10 A$ = "BASIC"
20 B$ = LEFT$(A$,3)
30 PRINT B$
will yield:
BAS
Also, see the MID$ and RIGHT$ functions elsewhere in this section.
6-112 GW-BASIC Reference Manual
LEN FUNCTION
PURPOSE:
Returns the number of characters in X$. Nonprinting characters and
blanks are also counted.
SYNTAX:
Y = LEN(X$)
EXAMPLE:
The function:
10 X$ = "PORTLAND, OREGON"
20 PRINT LEN(X$)
will yield:
16
Commands, Statements, Functions, and Variables 6-113
LET STATEMENT
PURPOSE:
Assigns the value of an expression to a variable.
SYNTAX:
[LET ]<variable> = <expression>
NOTES:
Notice that the word LET is optional; in other words, the equal sign is
sufficient for assigning an expression to a variable name.
EXAMPLES:
110 LET D =12
120 LET E = 12/\ 2
130 LET F = 12/\4
140 LET SUM = D+E+F
or:
110D=12
120 E = 12/\2
130 F=12/\4
140 SUM=D+E+F
6-114 GW-BASIC Reference Manual
LINE STATEMENT
PURPOSE:
Draws a line or box on the screen.
SYNTAX:
LINE [(X1, Y1)] - (X2, Y2) [,[ <color>][, B[F]][, <style> ]]
(X1 ,Y1) is the coordinate for the starting point of the line.
<color> is the number of the color in which the line should be drawn.
(See "COLOR Statement" earlier in this section for more information.) If
the ,B or ,BF option is used, the box is drawn in this color.
,B draws a box in the foreground, with the pOints (X1 ,Y1) and (X2,Y2) as
opposite corners.
NOTES:
When out-of-range coordinates are given, line clipping occurs. Points
plotted outside the screen or viewport limits do not appear.
The <style> argument provides dashed lines. Each time LINE stores a
point on the screen, it will use the current circulating bit in <style>. If
that bit is 0, storage does not occur. If the bit is a 1, then a normal
storage occurs. After each point, the next bit position in <style> is
selected.
Since a a bit in <style> does not clear out the old contents, the user
may wish to draw a background line before a 'styled' line to force a
known background.
<style> operates only for normal lines and boxes; it has no effect on
filled boxes.
EXAMPLES:
The following examples assume a screen 320 pixels wide by 200 pixels
high. The statement:
10 LINE - (X2,Y2)
draws a line from the last point to X2,Y2 in the foreground color. This is
the simplest form of the LI NE statement. The statement:
draws a diagonal line across the screen (downward, from left to right).
The statement:
draws a line from left to right across the screen. The statement:
10 CLS
20 LINE - (RND*319,RND*199),RND*4
30GOT020
draws a box in the foreground (note that the color is not included). The
statement:
draws a dashed line from the upper left corner of the screen to the
center.
Commands, Statements, Functions, and Variables 6-117
PURPOSE:
Reads the input of an entire line (up to 254 characters) from the
keyboard to a string variable, without the use of delimiters.
SYNTAX:
LINE INPUT[;][ <"prompt string">;] <string variable>
NOTES:
< "prompt string"> is a string literal that is printed on the screen before
input is accepted. A question mark is not printed unless it is part of
< "prompt string">. All input from the end of < "prompt string"> to the
carriage return is assigned to <string variable>. If a linefeed/carriage
return sequence (in this order only) is encountered, both characters are
echoed; however, the carriage return is ignored, the linefeed is put into
<string variable>, and data input continues.
EXAMPLE:
See "LINE INPUT# Statement".
6-118 GW-BASIC Reference Manual
PURPOSE:
Reads an entire line (up to 254 characters), without delimiters, from a
sequential disk data file to a string variable.
SYNTAX:
LINE INPUT <file number>,<string variable>
NOTES:
<file number> is the number under which the file was OPENed.
<string variable> is the variable name to which the line will be assigned.
LINE INPUT# is especially useful if each line of a data file has been
broken into fields, or if a GW-BASIC program saved in ASCII format is
being read as data by another program. (See "SAVE Command" later in
this section for more information.)
EXAMPLE:
The routine:
will yield:
LIST COMMAND
PURPOSE:
Lists all or part of the program currently in memory on the screen.
SYNTAX 1:
LIST [<line number> 1
SYNTAX 2:
LIST [<line number>][ - [<line number> llL <device> 1
NOTES:
GW-BASIC always returns to command level after a LIST is executed.
Syntax 1
Syntax 2
EXAMPLES:
The following statements illustrate Syntax 1:
LIST
LIST 500
LIST 150-
LIST -1000
LIST 150-1000,"LPT1"
!
\
Commands, Statements, Functions, and Variables 6-121
LUST COMMAND
PURPOSE:
Lists all or part of the program currently in memory at the line printer.
SYNTAX:
LLiST [<line number>[ - [<line number> III
NOTES:
LLiST assumes a 132-character-wide printer.
The options for LLiST are the same as for LIST, except that the
<device> is always LPT1:. Therefore, a <device> specification is
illegal in the LLiST command.
EXAMPLE:
See the examples for "LIST Statement" .
6-122 GW-BASIC Reference Manual
LOAD COMMAND
PURPOSE:
Loads a file from disk or RAM cartridge into memory.
SYNTAX:
LOAD <filespec>[,R]
NOTES:
The <filespec> must include the filename that was used when the file
was saved. If an extension is not specified, MS-DOS supplies .BAS as
the extension.
The device specifications for cartridge port 1 and cartridge port 2 are
CART1: and CART2:, respectively.
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 loading 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 chain several programs (or segments of the same
program). Information may be passed between the programs using their
disk data files.
EXAMPLES:
The statement:
LOAD "STRTRK",R
LOAD "B:MYPROG"
loads the program MYPROG from the disk in drive B, but does not run
the program. The statement:
loads the program TEST from the RAM cartridge in cartridge port 1.
Commands, Statements, Functions, and Variables 6-123
LOC FUNCTION
PURPOSE:
With random disk files, LOC returns the actual record position within the
file number of the last record read or written.
With sequential files, LOC returns the current byte position in the file,
divided by 128.
When a file is opened for APPEND or OUTPUT, LOC returns the length of
the file divided by 128.
SYNTAX:
X = LOC( <file number»
where <file number> is the number under which the file was OPENed.
NOTES:
When a file is opened for sequential input, GW-BASIC reads the first
sector of the file; consequently, LOC will return a 1 even before any input
from the file occurs.
EXAMPLE:
200 IF LOC(1»50 THEN STOP
6-124 GW-BASIC Reference Manual
LOCATE STATEMENT
PURPOSE:
Moves the cursor to the specified position. Optional parameters turn the
blinking cursor on and off and define the vertical start and stop lines.
SYNTAX:
LOCATE [<row>][.[ <col> ][,[ <cursor>][.[ <start> l[,<stop> llll
NOTES:
Any value outside the specified ranges will result in an "Illegal function
call" error. In this case, previous values are retained.
Note that the <start> and <stop> lines are the raster lines that are lit on
the screen. A wider range between the start and stop lines will produce
a taller cursor, such as one that occupies an entire character block.
If the <start> line is given but the <stop> line is omitted, <stop>
assumes the same value as <start>.
Commands, Statements, Functions, and Variables 6-125
EXAMPLES:
The statement:
10 LOCATE 1,1
moves cursor to the upper left corner of the screen. The statement:
20 LOCATE" 1
30 LOCATE ",7
leaves the position and cursor visibility unchanged. The cursor is set to
display at the bottom of the character starting and ending on raster line
7. The statement:
40 LOCATE 5,1,1,0,7
moves the cursor to line 5, column 1, and turns the cursor on. The cursor
will cover the entire character ceil, starting at scan line 0 and ending on
scan line 7.
6-126 GW-BASIC Reference Manual
LOF FUNCTION
PURPOSE:
Returns the length of the file in bytes.
SYNTAX:
X = LOF( <file number> )
<file number> is the number under which the file was OPENed.
EXAMPLE:
In the following example:
the variables REC and RECSIZ contain the record number and record
length, respectively. The calculation determines whether the specified
record is beyond the end-of-file.
Commands, Statements, Functions, and Variables 6-127
LOG FUNCTION
PURPOSE:
Returns the natural logarithm of X. X must be greater than zero.
SYNTAX:
Y = LOG(X)
EXAMPLE:
The function:
PRINT LOG(45/7)
will yield:
1.860752
6-128 GW-BASIC Reference Manual
LPOS FUNCTION
PURPOSE:
Returns the current position of the line printer's print head within the line
printer buffer.
SYNTAX:
X = LPOS(I)
NOTES:
LPOS does not necessarily give the physical position of the print head.
EXAMPLE:
100 IF LPOS(X»60 THEN LPRINT CHR$(13)
Commands, Statements, Functions, and Variables 6-129
PURPOSE:
Prints data at the line printer.
SYNTAX:
LPRINT [<list of expressions> 1
NOTES:
Same as PRINT and PRINT USING, except that the output goes to the
line printer.
EXAMPLES:
See PRINT and PRINT USING later in this section.
6-130 GW-BASIC Reference Manual
PURPOSE:
Moves data from memory to a random file buffer (in preparation for a
PUT statement) and left-justifies or right-justifies the data in the buffer.
SYNTAX:
LSET <string variable> = <string expression>
RSET <string variable> = <string expression>
NOTES:
If <string expression> requires fewer bytes than were fielded to
<string variable>, LSET left-justifies the string in the field, and RSET
right-justifies the string. (Spaces are used to pad the extra positions.) If
the string is too long for the field, characters are dropped from the right.
EXAMPLES:
150 LSET A$ = MKS$(AMT)
160 LSET D$ = DESC$
Note: LSET or RSET may also be used with a nonfielded string variable
to left-justify or right-justify a string in a given field. For example, the
program lines:
110 A$ = SPACE$(20)
120 RSET A$= N$
MERGE COMMAND
PURPOSE:
Merges a specified disk file into the program currently in memory.
SYNTAX:
MERGE <filespec>
NOTES:
The <filespec> must include the filename used when the file was
saved. The file must have been saved in ASCII format. If it was not, a
"Bad file mode" error occurs.
If any lines in the disk file have the same line numbers as lines in the
program in memory, the lines from the file on disk will replace the
corresponding lines in memory. (The MERGE process may be thought
of as "inserting" the program lines on disk into the program in memory.)
EXAMPLE:
The command:
MERGE "NUMBRS"
inserts, by sequential line number, all lines in the program NUMBRS into
the program currently in memory.
6-132 GW-BASIC Reference Manual
MID$ STATEMENT
PURPOSE:
Replaces a portion of one string with another string.
SYNTAX:
MID$«string exp1>,I[,J]) = <string exp2>
NOTES:
The characters in <string exp1 >, beginning at position I, are replaced
by the characters in <string exp2>.
EXAMPLE:
The routine:
will yield:
KANSAS CITY, KS
Commands, Statements, Functions, and Variables 6-133
MID$ FUNCTION
PURPOSE:
Returns a string J characters long from X$, beginning with the Ith
character.
SYNTAX:
Y$ = MIO$(X$,I[,J])
NOTES:
I and J must be in the range 1 to 255. If J is omitted or if there are fewer
than J characters to the right of the Ith character, all rightmost charac-
ters beginning with the Ith character are returned. If I is greater than the
number of characters in X$ (LEN(X$)), MIO$ returns a null string.
Also see the LEFT$ and RIGHT$ functions elsewhere in this section.
EXAMPLE:
The function:
10 A$ = ''GOO~ "
20 B$ = "MORNING EVENING AFTERNOON"
30 PRINT A$;MI0$(B$,9,7)
will yield:
GOOD EVENING
6-134 GW-BASIC Reference Manual
MKDIR STATEMENT
PURPOSE:
Creates a new directory in the MS-DOS file system.
SYNTAX:
MKDIR <pathname>
NOTES:
MKDIR works exactly like the DOS command MKDIR.
Possible errors:
EXAMPLES:
The following statements will create the subdirectories SALES and
ACCOUNTING.
MKDIR ''\SALES''
Commands, Statements, Functions, and Variables 6-135
PURPOSE:
Converts numeric values to string values.
SYNTAX:
X$ = MKI$«integer expression»
X$ = MKS$( <single precision expression»
X$ = MKD$«double precision expression»
NOTES:
Any numeric value placed in a random file buffer with an LSET or RSET
statement must be converted to a string. MKI$ converts an integer to a
2-byte string. MKS$ converts a single precision number to a 4-byte
string. MKD$ converts a double precision number to an 8-byte string.
See also "CVI, CVS, and CVD Functions" earlier in this section.
EXAMPLE:
90 AMT = (K + T)
100 FIELD #1,8 AS D$,20 AS N$
110 LSET D$ = MKS$(AMT)
120 LSET N$ = A$
130 PUT #1
6-136 GW-BASIC Reference Manual
NAME STATEMENT
PURPOSE:
Changes the name of a disk or a RAM cartridge file.
SYNTAX:
NAME <old filename> AS <new filename>
NOTES:
<old filename> must exist and <new filename> must not exist;
otherwise, an error will result. Also, <old filename> must be closed
before rename. The same open file check is used as in OPEN and KILL,
described elsewhere in this section.
A file may not be renamed with a new drive designation. If a new drive
designation is attempted, a "Rename across disks" error will be gener-
ated. After a NAME Statement, the file exists on the same disk, in the
same area of disk space, with the new name.
Pathnames are not allowed. That is, only files in the current directory may
be renamed. Giving a path will result in a "Bad filename" error.
EXAMPLE:
In the example:
the file that was formerly named ACCTS will now be named LEDGER.
Commands, Statements, Functions, and Variables 6-137
NEW COMMAND
PURPOSE:
Deletes the program currently in memory, clears all variables and
cancels the definitions of all animation objects.
SYNTAX:
NEW
NOTES:
NEW is entered in direct mode to clear memory before entering a new
program. GW-BASIC always returns to command level after a NEW is
executed.
EXAMPLE:
NEW
6-138 GW-BASIC Reference Manual
OBJECT FUNCTION
PURPOSE:
Returns the current value of a specific attribute for a given object.
SYNTAX:
X = OBJECT «object number>, <attribute number»
NOTES:
See the description of the DEF OBJECT statement for information on
object numbers, and of the OBJECT statement for information on
attributes.
EXAMPLE:
The function:
10 X = OBJECT (1,5)
sets variable X equal to the value of attribute 5, the period of view
attribute, for object number 1.
Commands, Statements, Functions, and Variables 6-139
OBJECT STATEMENT
PURPOSE:
Specifies one or more attributes of the specified object.
SYNTAX:
OBJECT <object number>,<attribute number> = <value> [,<attribute
number> = <value>, ... J
NOTES:
The attributes for an object are as follows:
1 Current X position o
2 Current Y position o
3 Terminal X position o
4 Terminal Y position o
5 Period of view o (infinite)
6 X offset o
7 Yoffset o
8 Current view 1
9 Transparency o (transparent)
10 Speed o
The values of all attributes (except transparency) can be integer or real
numbers. GW-BASIC converts the values to the closest usable value.
For example, specifying a pixel location of 1.3 rounds to a pixel location
of 1 internally. The OBJECT function returns the rounded values.
The position attributes are given in terms of logical units which define the
resolution of the current window. When the current window includes the
entire screen and the resolution is 320 X 200 then a horizontal logical unit
is 1/320 of the screen width and a vertical logical unit is 1/200 of the
screen height.
The current X and Y position attributes select the location for the object
within the current window. If the speed attribute is greater than zero, the
current X and Y position attributes select the origin for the object and the
terminal X and Y position attributes select the destination for the object.
The X and Y offset values specify the point of the location indicated by
the current X and Y position attributes. The X and Y offset attributes are
relative to the center of the rectangle formed by the <x size> and
<y size> attributes of the DIM OBJECT statement. The offset is the
distance from location (0,0) at the center of the rectangle to the reference
point of the object.
For example, the reference point for an arrow would be at the tip of the
arrowhead. If the arrow pointed down and right and was 10 logical units
in length and height, then the X and Y offsets should be 5 and 5 units,
respectively, to place the tip of the arrowhead at the location specified
by the current X and Y position attributes.
The current view is the number of one of the arrays in the array list
included with the DEF OBJECT statement. The first array in the list is
view number 1, the second array is view number 2, and so on. If the
period of view attribute is zero, the current view is the only view shown.
Otherwise, the current view is the first view shown before the other views
are shown in sequence. After displaying the last view, the cycle begins
again with the first view.
The speed attribute is a real value given in logical units per second. The
a
default speed of causes the object to be stationary. Setting the speed
attribute to a value greater than a causes the object to move from the
current X and Y position to the terminal X and Y position at the specified
number of logical units per second.
See also the OBJECT function and the DIM OBJECT, DEF OBJECT,
START/STOP OBJECT, ARRIVAL, CLIP, and COLLISION statements
described elsewhere in this section.
Commands, Statements, Functions, and Variables 6-141
EXAMPLE:
The statement:
OCT$ FUNCTION
PURPOSE:
Returns a string that represents the octal value of the decimal argument.
X is rounded to an integer before OCT$(X) is evaluated.
SYNTAX:
Y$ = OCT$(X)
EXAMPLE:
The function:
PRINT OCT$(24)
will yield:
30
For details on hexadecimal conversion, see the HEX$ function earlier in
this section.
Commands, Statements, Functions, and Variables 6-143
ON ARRIVAL STATEMENT
PURPOSE:
Specifies the first line number of a subroutine to be performed when an
object arrives at the destination indicated in an OBJECT statement.
SYNTAX:
ON ARRIVAL [«object number»] GOSUB <line number>
NOTES:
A <line number> of 0 disables the arrival event testing specified in the
ON ARRIVAL statement.
If an ARRIVAL OFF statement has been executed, the arrival event is not
discovered and the GOSUB is not performed (see ':A.RRIVAL
Statement").
EXAMPLES:
The statement:
ON CLIP STATEMENT
PURPOSE:
Specifies the first line number of a subroutine to be performed when 9.n
object exceeds (is clipped at) the border of the current window.
SYNTAX:
ON CLIP [( <object number»] GOSUB <line number>
NOTES:
A <line number> of 0 disables the trapping of the clipping event
specified in the ON CLIP statement.
When the ON CLIP statement does not include an object number, the
subroutine is executed when any object exceeds the boundary of the
current window.
One use of the ON CLIP statement is to latch the clipping status of the
objects on the screen. When any object specified in an ON CLIP
statement exceeds the boundary of the current viewport, GW-BASIC
makes a copy of the internal clip flags of all objects which have
exceeded the boundary of the current viewport since the last time the
status was latched. In this respect, ON CLIP is the same as the
CLlP( -1) function. (See the CLIP function in this section.)
If a CLIP OFF statement has been executed, the clipping event is not
discovered and the GOSUB is not performed (see "CLIP Statement").
EXAMPLES:
The statement:
ON COLLISION STATEMENT
PURPOSE:
To specify the first line number of a subroutine to be performed when an
object collides with another object.
SYNTAX:
ON COLLISION [( <object number 1>[, <object number 2>])]
GOSUB <line number>
<object number 1> and <object number 2> are the numbers of objects
being monitored for possible collisions.
NOTES:
A <line number> of 0 disables the collision event testing specified in the
ON COLLISION statement.
A collision is detected only if two objects overlap when they are actually
being drawn on the screen. Fast-moving objects may move several
pixels at each update, and may actually cross paths without overlapping
on the screen.
A collision of two objects can cause more than one event to be trapped.
Multiple events can also occur if more than two objects collide "simul-
taneously" (overlap during the same screen update).
another object since the last time the status was latched. In this respect,
ON COLLISION is the same as the COLLISION( -1) function. (See the
COLLISION function in this section.)
EXAMPLES:
The statement:
ON COM STATEMENT
PURPOSE:
Specifies the first line number of a subroutine to be performed when
activity occurs on a communications channel.
SYNTAX:
ON COM(n) GOSUB <line number>
NOTES:
A <line number> value of zero disables the communications event trap.
When an event trap occurs (in other words, when the GOSUB is
performed), an automatic COM STOP is executed so recursive traps
cannot take place. The RETURN from the trapping subroutine will
automatically perform a COM ON statement unless an explicit COM OFF
was performed inside the subroutine.
Event trapping does not take place when GW-BASIC is not executing a
program. Also, event trapping is automatically disabled when an error
trap occurs.
EXAMPLE:
The statement:
will cause GW-BASIC to transfer control to line 1000 when the system
receives a character from the first RS-232-C module.
6-152 GW-BASIC Reference Manual
PURPOSE:
Enables error handling and specifies the first line of the error handling
routine.
SYNTAX:
ON ERROR GOTO <line number>
NOTES:
After error handling has been enabled, all errors detected, including
direct mode errors (for example, syntax errors), will cause a jump to the
specified error handling routine. If <line number> does not exist, an
"Undefined line" error results.
EXAMPLE:
10 ON ERROR GOTO 1000
(
Commands, Statements, Functions, and Variables 6-153
PURPOSE:
Branches to one of several specified line numbers, depending on the
value returned when an expression is evaluated.
SYNTAX:
ON <expression> GOTO <list of line numbers>
NOTES:
The value of <expression> determines which line number in the list will
be used as the destination for branching. For example, if the value of
<expression> is 3, the third line number in the list will be the destination
of the branch. (If the value is a noninteger, the fractional portion is
rounded.)
In the ON ... GOSUB statement, each line number in the list must be the
first line number of a subroutine.
EXAMPLE:
100 ON L-1 GOTO 150,300,320,390
6-154 GW-BASIC Reference Manual
ON KEY STATEMENT
PURPOSE:
Specifies the first line number of a subroutine to be performed when a
specified key is pressed.
SYNTAX:
ON KEY(n) GOSUB <line number>
(n) is the number of a function key, as defined by the KEY (n) statement.
NOTES:
A <line number> of 0 disables the event trap.
If a KEY(n) OFF statement has been executed for the specified key, (see
"KEY(n) Statement"), the keystroke is not discovered and the GOSUB is
not performed.
If a KEY STOP statement has been executed for the specified key, (see
"KEY(n) Statement"), the GOSUB is not performed, but will be remem-
bered and performed as soon as a KEY(n) ON statement is executed.
Event trapping does not take place when GW-BASIC is not executing a
program. Also, event trapping is automatically disabled when an error
trap occurs.
EXAMPLE:
10 KEY 4, "SCREEN 0,0" 'assigns softkey 4
20 KEY(4) ON 'enables event trapping
(key 4 pressed)
ON PLAY STATEMENT
PURPOSE:
Specifies the first line of a subroutine to be performed when the number
of notes in the background music queue goes below a specified value.
This statement enables continuous music during program execution.
SYNTAX:
ON PLAY(n) GOSUB <line number>
<line number> is the statement line number of the play event trap
subroutine.
NOTES:
The following rules apply to event trapping on the background music
queue:
1. A play event trap is issued only when playing background music (in
other words, PLAY "MB ... ). Play event traps are not issued when
running in Music Foreground (in other words, default case, or PLAY
"MF... ).
The ON PLAY statement uses only voice 1 to test the number of notes in
the background music queue.
See also the PLAY statement for information on the PLAY ON, PLAY OFF,
and PLAY STOP statements.
EXAMPLE:
ON PLAY (5) GOSUB 900
ON STRIG STATEMENT
PURPOSE:
Specifies the first line number of a subroutine to be performed when the
joystick trigger or mouse switch is pressed.
SYNTAX:
ON STRIG(n) GOSUB <line number>
a A right
2 A left
4 B right
6 B left
NOTES:
A <line number> of a disables the event trap.
When an event trap occurs (in other words, when the GOSUB is
performed), an automatic STRIG STOP is executed so that recursive
traps cannot take place. The RETURN from the trapping subroutine will
automatically perform a STRIG ON statement unless an explicit STRIG
OFF was performed inside the subroutine.
Event trapping does not take place when GW-BASIC is not executing a
program. Also, event trapping is automatically disabled when an error
trap occurs.
EXAMPLE:
The statement:
will cause GW-BASIC to transfer control to line 1000 when the system
detects that the button has been pressed on the first joystick.
Commands, Statements, Functions, and Variables 6-159
PURPOSE:
Causes periodic event traps.
SYNTAX:
ON TIMER(n) GOSUB <line number>
<line number> is the statement line number of the TIMER event trap
subroutine.
NOTES:
These statements provide an interval timer for applications programs.
TIMER OFF disables TIMER event trapping and TIMER STOP suspends
TIMER event trapping. If the specified time elapses after a TIMER STOP
statement is executed, then GW-BASIC executes the ON TIMER sub-
routine immediately after the next TIMER ON statement.
EXAMPLE:
Display the time of day on line 1 every minute.
OPEN STATEMENT
PURPOSE:
Allows I/O to a file or device.
SYNTAX:
OPEN <mode>,[#]<file number>,<filespec>[,<record length>]
Character Meaning
The <record length> cannot exceed the maximum set with IS: at start-
up. If the <record length> option is not used, the default length is 128
bytes.
NOTES:
A disk file must be OPENed before any disk 1/0 operation can be
performed on that file. OPEN allocates a buffer for 1/0 to the file or
device and determines the mode of access that will be used with the
buffer.
EXAMPLES:
10 OPEN "1",2, "INVEN"
PURPOSE:
Opens and initializes a communications channel for input/output.
SYNTAX:
OPEN "COMn: [<speed> ][,[ <parity>][,[ <data> ][,[ <stop> ][,RS]
[,CS[m]][,DS[m]][,CD[m]][,BIN][,ASC][,LF]]]]" AS [#]<device
number>
<data> designates the number of bits per byte. Valid entries are 7 or 8.
<stop> designates the stop bit. The value of this parameter must be 1
or 2.
BIN opens the device in binary mode. BIN is selected by default unless
ASC is specified. See "NOTES" for further discussion of BIN.
ASC opens the device in ASCII mode. See "NOTES" for further
discussion of ASC.
NOTES:
The OPEN COM statement must be executed before a device can be
used for RS-232-C communication.
Commands, Statements, Functions, and Variables 6-163
Any syntax errors in the OPEN COM statement will result in a "Bad file
name" error. The incorrect parameter will not be shown.
A "Device timeout" error will occur if Data Set Ready (DSR) is not
detected.
The m argument for the CS[m], DS[mJ, and CD[m] options specifies an
interval in milliseconds. After executing an OPEN COM statement,
GW-BASIC checks the specified line signal for this amount of time
before returning a "Device timeout" error. The value of m can range from
o to 65535. The status of these line signals is not checked if m is set to 0
or if m is omitted.
In the BIN mode, tabs are not expanded to spaces, a carriage return is
not forced at the end-of-line, and CTRL-Z is not interpreted as the end-of-
file and CTRL-Z is not sent when the channel is closed.
In' ASC mode, tabs are expanded, carriage returns are forced at the end-
of-line, CTRL-Z is treated as the end-of-file, XON/XOFF protocol is
supported (if enabled), and CTRL-Z is sent when the channel is closed.
EXAMPLE:
The statement:
10 OPEN "COM1:9600,N,8,1,BIN" AS 2
PURPOSE:
Declares the minimum value for array subscripts.
SYNTAX:
OPTION BASE n
n is 1 or O.
NOTES:
The default base is O. If the statement:
OPTION BASE 1
The OPTION BASE statement must be coded before you define or use
any arrays.
EXAMPLE:
10 OPTION BASE 1
Commands, Statements, Functions, and Variables 6-165
OUT STATEMENT
PURPOSE:
Sends a byte to a machine output port.
SYNTAX:
OUTI,J
EXAMPLE:
The BASIC statement:
MOV DX,12345
MOVAL,255
OUT DX,AL
6-166 GW-BASIC Reference Manual
PAINT STATEMENT
PURPOSE:
Fills a graphics figure with the color specified.
SYNTAX:
PAINT «xstart>,<ystart»[,<paint color>[,<border color>]
[,<background> ]]
NOTES:
Painting is complete when a line is painted without changing the color of
any pixel; in other words, the entire line is equal to the paint color.
The PAl NT command can be used to fill any figure, but painting jagged
edges or very complex figures may result in an "Out of Memory" error. If
this happens, the CLEAR statement must be given to increase the
amount of stack space available.
PAINT supports "tiling". Like LINE, PAINT looks at a "tiling" mask each
time a pOint is put down on the screen. If <paint color> is a string
formula, then "tiling" is performed as follows.
The tile mask is always 8 bits wide and may be from 1 to 64 bytes long.
Each byte in the tile string masks 8 bits along the X axis when putting
down points. Each byte of the tile string is rotated as required to align
along the Y axis such that tile_byte_mask = Y MOD tile_length.
Rotating each byte of the tile string is done so that the tile pattern is
replicated uniformly over the entire screen (as if the statement PAINT
(0,0) ... were used).
Commands, Statements, Functions, and Variables 6-167
x increases -->
Bit of tile byte
X,V 8 7 6 5 4 3 2
0,0 x x x x x x x x Tile byte 1
0,1 x x x x x x x x Tile byte 2
0,2 x x x x x x x x Tile byte 3
In modes with a resolution of 1 bit per pixel (modes 2,3, and 7) (see the
sample screen below), the screen can be painted with 'x's by the
following statement:
PAINT
(320,100),CHR$(&H81) + CHR$(&H42) + CHR$(&H24) + CHR$
(&H18) + CHR$(&H18) + CHR$(&H24) + CHR$(&H42) + CHR$(&H81)
x increases -->
Occasionally, you may want to tile-paint over an already painted area that
is the same color as two consecutive lines in the tile pattern. Normally,
paint quits when it encounters two consecutive lines of the same color as
the point being set (the point is surrounded). It would not be possible to
draw alternating blue and red lines on a red background without the
<background>. Paint would stop as soon as the first red pixel was
drawn. Specifying red [CHR$(&HAA)] as the background_attribute
allows the red line to be drawn over the red background.
You cannot specify more than two consecutive bytes in the tile string that
match the <background>. Specifying more than two will result in an
"Illegal function call" error.
EXAMPLE:
The statement:
10 PAINT (5,15),2,0
paints the figure at coordinates 5,15 with color 2 and border color O.
Commands, Statements, Functions, and Variables 6-169
PALETTE STATEMENT
PURPOSE:
Changes one of the colors in the palette.
SYNTAX:
PALETTE [<palette number>, <color number> 1
NOTES:
The color palette is a table consisting of 16 integer (two-byte) values.
When you first power-up your Mindset Personal Computer, the system
uses default values for <palette number> and <color number>. The
system also uses the default values when you use the PALETTE
statement without specifying the palette number or color number. Table
6-3 describes the default color palette. See the PALETTE USING
statement for an explanation of the hexadecimal color values.
The <color number> index selects a color from the reference palette.
The <palette number> index selects a color in the user's palette to
be replaced with the color selected by the <color number> index.
GW-BASIC uses the colors in the user's palette for the screen display.
EXAMPLE:
The statement:
PAtETIEO,2
changes color 0 in the user's palette to color 2 from the reference palette.
Commands, Statements, Functions, and Variables 6-171
PURPOSE:
Specifies new colors by assigning a set of array values to the user's
palette.
SYNTAX:
PALETTE USING <array name>«array index»
<array name> is the name of the array containing new information for
tre user's color palette. <array index> specifies the element in the
array to use as the first position in the user's palette.
NOTES:
The color palette is a table consisting of 16 integer (two-byte) values.
When you first power-up your Mindset Personal Computer, the system
uses default values for the color palette and color numbers. See Table
6-3 under the description of PALETTE for the default color palette
arrangement.
The PALETTE USING statement transfers color values from the array to
the user's palette. The <array index> parameter determines which
element in the array becomes the first element in the user's palette.
The colors in the palette are initially the same for operation with either an
RGB color monitor or a television. Use an array to rearrange the user's
palette using the colors from the reference palette. This array should
contain numbers in the range 0 to 15 in the upper 4 bits to specify the
RGB colors for the user's palette. The number of colors for an RGB
monitor is fixed at 16, but the user can specify up to 512 different colors
for operation with a television. The lower 9 bits in each palette definition
The diagram below shows the format for the 16-bit word that defines
each color in the user's palette. See Table 6-3 in the description of the
PALETTE statement for a list of the default hexadecimal color values.
Three bits control each primary color for television operation. Each bit is
worth twice that of the next lower bit for a given color. For example, bit 0
sets the value of the red component to 1, bit 1 adds 2 to the red value,
and bit 2 adds 4. Therefore, the palette entry for the most intense red is
7. Similarly, the value for the most intense white requires all 9 bits to be
set for a value of 511.
EXAMPLE:
The statement:
PEEK FUNCTION
PURPOSE:
Returns the byte read from memory location (I).
SYNTAX:
X = PEEK(I)
NOTES:
The returned value is an integer in the range 0 to 255. I must be in the
range 0 to 65535. I is the offset from the current segment, which was
defined by the last DEF SEG statement. For the interpretation of a
negative value of I, see "VARPTR Function" later in this section.
EXAMPLE:
A = PEEK( &H5AOO)
6-174 GW-BASIC Reference Manual
PLAY STATEMENT
PURPOSE:
Plays music as specified by <string expression>.
SYNTAX:
PLAY [<string1 >][, <string2>[, <string3>[, <string4>]]]
PLAY ON
PLAY OFF
PLAY STOP
NOTES:
PLAY uses a concept similar to that in DRAW by embedding a Music
Macro Language into one statement. A set of subcommands, used as
part of the PLAY statement itself, specifies the particular action to be
taken.
Subcommand Explanation
Subcommand Explanation
N <n> a
Plays note n. n may range from through 84
(because in the 7 possible octaves there are 84
a
notes). n = means a rest.
Subcommand Explanation
PLAY OFF disables event trapping and PLAY STOP suspends event
trapping. If the number of notes in the background music queue goes
below the specified value after a PLAY STOP statement, the subroutine is
executed immediately after the next PLAY ON statement.
EXAMPLES:
PLAY "XA$;"
PLAY FUNCTION
PURPOSE:
Returns the number of notes currently in the background music queue.
SYNTAX:
I = PLAY(n)
NOTES:
PLAY(n) will return a when in Music Foreground mode.
EXAMPLE:
The function:
1= PLAY(1)
PMAP FUNCTION
PURPOSE:
Maps logical (world) coordinates to physical coordinates or physical
coordinates to world coordinates.
SYNTAX:
X = PMAP (I,n)
n Returned Value
NOTES:
The WINDOW statement defines the world coordinates and the VIEW
statement defines the physical coordinates. PMAP provides a simple
method of translating coordinate specifications from one system to the
Gther.
EXAMPLE:
The statement:
10 X = PMAP (32,2)
POINT FUNCTION
PURPOSE:
Reads the color value of a pixel from the screen. If the specified point is
out of range, the value -1 is returned.
SYNTAX 1:
I = POINT «xcoordinate>, <ycoordinate»
SYNTAX 2:
I = POINT (n)
n Returned Value
EXAMPLES:
10 SCREEN 1
20 FOR C=OTO 3
30 PSET (10,10),C
40 IF POINT(10,10)<>C THEN PRINT "Broken!"
50 NEXT C
5 SCREEN 2
10 IF POINT(I,I)<>O THEN PRESET (1,1)
ELSE PSET (1,1)
'invert current state of a point
20 PSET (1,1),1- POINT(I,I) 'another way to invert a point
Commands, Statements, Functions, and Variables 6-181
POKE STATEMENT
PURPOSE:
Writes a byte into a memory location.
SYNTAX:
POKE I,J
NOTES:
I and J are integer expressions. The expression I represents the address
of the memory location and J is the data byte. I must be in the range
- 32768 to 65535. I is the offset from the current segment, which was
set by the last DEF SEG statement. For the interpretation of the negative
values of I, see "VARPTR Function" later in this section.
EXAMPLE:
10 POKE &H5AOO,&HFF
6-182 GW-BASIC Reference Manual
POS FUNCTION
PURPOSE:
Returns the current horizontal (column) position of the cursor.
SYNTAX:
I = POS(X)
NOTES:
The leftmost position is 1. X is a dummy argument. To return the current
line position of the cursor, use the CSRLlN function.
EXAMPLE:
IF POS(X»60 THEN BEEP
Commands, Statements, Functions, and Variables 6-183
PRESET STATEMENT
PURPOSE:
Draws a specified point on the screen. PRESET works exactly like PSET,
except that if the <color> is not specified, the background color is
selected.
SYNTAX:
PRESET «xcoordinate>, <ycoordinate»[, <color> 1
<color> is the number assigned to the color to be used for the specified
point.
NOTES:
If an out-of-range coordinate is given, clipping occurs. Points plotted
outside the screen or viewport limits do not appear.
For example, if the most recent point referred to were (0,0), STEP (10,0)
would refer to a point offset 10 from X and 0 from Y.
EXAMPLE:
5 REM DRAW A LINE FROM (0,0) TO (100,100)
10 FOR I =0 TO 100
20 PRESET (1,1),1
30 NEXT
This example draws a line from (0,0) to (100,100) and then erases that
line by overwriting it with the background color.
6-184 GW-BASIC Reference Manual
PRINT STATEMENT
PURPOSE:
Displays data on the screen.
SYNTAX:
PRINT [<list of expressions> 1
NOTES:
If <list of expressions> is omitted, a blank line is printed. If
<list of expressions> is included, the values of the expressions are
printed on the screen. The expressions in the list may be numeric and/or
string expressions. (Strings must be enclosed in quotation marks.)
Quotation marks cannot be used as part of the string because they are
used as string delimiters.
Print Positions
EXAMPLES:
In Example 1, the routine:
10X=5
20 PRINT X + 5,X - 5,X*( - 5),X /\5
30END
will yield:
10 o -25 3125
In this example, the commas in the PRINT statement cause each value
to be printed at the beginning of the next print zone.
10 INPUT X
20 PRINT X "SQUARED IS" X!\2 ''AND'';
30 PRINTX "CUBED IS" X/\3
40 PRINT
50 GOTO 10
will yield:
?9
9 SQUARED IS 81 AND 9 CUBED IS 729
? 21
21 SQUARED IS 441 AND 21 CUBED IS 9261
In this example, the semicolon at the end of line 20 causes the PRINT
statements on lines 20 and 30 to be printed on the same line. Line 40
causes a blank line to be printed before the next prompt.
10 FOR X=1 TO 5
20 J=J +5
30 K=K+10
40 ?J;K;
50 NEXT X
will yield:
5 10 10 20 15 30 20 40 25 50
continued on next page
6-186 GW-BASIC Reference Manual
PURPOSE:
Prints strings or numbers using a specified format.
SYNTAX:
PRINT USING <string exp>;<list of expressions>
NOTES:
<string exp> is a string literal (or variable) composed of special
formatting characters. These formatting characters (see below) deter-
mine the field and the format of the printed strings or numbers.
String Fields
Character Meaning
Numeric Fields
Character Meaning
Character Meaning
Character Meaning
EXAMPLES:
In Example 1, the statement
10 A$ = "LOOK":B$ = "OUT"
30 PRINT USING "!";A$;B$
40 PRINT USING "\ \";A$;B$
50 PRINT USING "\ \";A$;B$;"!!"
Commands, Statements, Functions, and Variables 6-191
will yield:
LO
LOOKOUT
LOOK OUT !!
10 A$ = "LOOK":8$ = "OUT"
20 PRINT USING "!";A$;
30 PRINT USING "&";8$
will yield :
LOUT
6-192 GW-BASIC Reference Manual
PURPOSE:
Writes data to a sequential file.
SYNTAX:
PRINT #<file number>,[USING <string exp>;]
<list of expressions>
NOTES:
<file number> is the number used when the file was OPENed for output.
<string exp> consists of formatting characters, as described under the
"PRINT USING Statement". The expressions in <list of expressions>
are the numeric and/or string expressions that will be written to the file.
PRINT # does not compress data. An image of the data is written to the
file, just as it would be displayed on the screen with a PRINT statement.
For this reason, be careful to delimit the data so it will be input correctly.
PRINT #1,A;B;C;X;Y;Z
(If commas are used as delimiters, any extra blanks inserted between
print fields will also be written to the file.)
PRINT #1,A$;B$
PRINT #1,A$;",";B$
CAMERA,93604 -1
PRINT #1,A$;B$
INPUT #1,A$,B$
PRINT #1,CHR$(34);A$;CHR$(34);CHR$(34);B$
;CHR$(34)
INPUT #1,A$,B$
The PRINT statement may also be used with the USING option to control
the format of the file. For example:
PRINT #1,USING"$$###.##,";J;K;L
PSET STATEMENT
PURPOSE:
Draws a point on the screen at the specified point in the specified color.
SYNTAX:
PSET «xcoordinate>, <ycoordinate»[, <color> 1
NOTES:
When GW-BASIC scans coordinate values, it allows them to extend
beyond the edge of the screen. However, values outside the integer
range - 32768 to 32767 will cause an "Overflow" error.
The coordinate (0,0) is always the upper left corner of the screen.
Therefore, the bottom left corner of the screen is 0,199 in screen modes 1
through 5 and 0,399 in screen modes 6 and 7.
PSET allows the <color> to be left off the command line. If <color> is
omitted, the default is the foreground color.
For example, if the most recent point specified were (0,0), PSET STEP
(10,0) would refer to a point at offset 10 from X and offset 0 from Y
EXAMPLE:
5 REM DRAW A SERIES OF POINTS FROM (0,0) TO (100,100)
10 FOR I =0 TO 100
20 PSET (1,1)
30 NEXT
This example draws a series of points from (0,0) to (100,100) and then
erases them by overwriting it with the background color.
6-196 ' GW-BASIC Reference Manual
PURPOSE:
Writes a record from a random buffer to a random access file.
SYNTAX:
PUT [# ]<file number>[, <record number>]
NOTES:
<file number> is the number under which the file was OPENed. If
<record number> is omitted, the record will assume the next available
record number (after the last PUT). The largest possible record number
is 16,777,215. The smallest record number is 1.
The GET and PUT statements allow fixed-length input and output for
GW-BASIC COM files. However, because of the low performance
associated with telephone line communications, you should normally not
use GET and PUT for telephone communication.
PURPOSE:
Used with the GET statement to transfer graphic images to and from the
screen.
SYNTAX:
PUT (X1 ,Y1),<array name>[,<action verb> 1
<array name> is the name of the array in which the object image was
stored with a graphics GET statement.
<action verb> is one of the following: PSET, PRESET, AND, OR, or XOR.
PRESET is the same as PSET, except that all pOints in the image are
inverted.
AND is used to transfer points from the array only where points already
exist from another image on the screen.
XOR causes the points on the screen to be inverted where a point exists
in the array image. This behavior is exactly like that of the cursor. When
an image is PUT against a complex background twice, the background
is restored unchanged. Thus, a user can move an object around the
screen without obliterating the background.
NOTES:
The graphics version of the PUT statement is the complement of the
graphics GET statement. It enables a program to transfer an object to
the screen from an object array.
EXAMPLE:
The statement:
10 PUT (10,10),FIGURE1, OR
places the object stored in the FIGURE1 array on the screen. The
statement places the upper left corner of the rectangle containing the
object at screen location (10,10). The <action verb>, OR, causes the
image to be superimposed over any images which are already on the
screen.
Commands, Statements, Functions, and Variables 6-199
RANDOMIZE STATEMENT
PURPOSE:
Reseeds the random number generator.
SYNTAX:
RANDOMIZE [<expression> 1
NOTES:
If <expression> is omitted, GW-BASIC suspends program execution
and asks for a value by printing:
EXAMPLES:
The routine:
10 RANDOMIZE
20 FOR I = 1 TO 5
30 PRINT RND;
40 NEXT I
RUN
will yield:
Note that the numbers your program produces may not be the same as
the ones shown here.
Commands, Statements, Functions, and Variables 6-201
READ STATEMENT
PURPOSE:
Reads values from a DATA statement and assigns them to variables.
(See "DATA Statement" earlier in this section for more information.)
SYNTAX:
READ <list of variables>
NOTES:
A READ statement must always be used in conjunction with a DATA
statement. READ statements assign variables to DATA statement values
on a one-to-one basis. READ statement variables may be numeric or
string variables, and the values read must agree with the variable types
specified. If they do not agree, a "Syntax error" will result.
The READ statement can act upon DATA statements in one of two ways:
either a single READ statement may access one or more DATA state-
ments (they will be accessed in order), or several READ statements may
access the same DATA statement. If the number of variables in <list of
variab'les> exceeds the number of elements in the DATA statement(s),
an "Out of data" error message is printed. If the number of variables
specified is fewer than the number of elements in the DATA statement(s),
subsequent READ statements will begin reading data at the first unread
element. If there are no subse_quent READ statements, the extra data is
ignored.
To reread DATA statements from the start, use the RESTORE statement
(see "RESTORE Statement" later in this section).
EXAMPLES:
In Example 1:
80 FOR I = 1 TO 10
90 READ A(I)
100 NEXT I
110 DATA 3.08,5.19,3.12,3.98,4.24
120 DATA 5.08,5.55,4.00,3.16,3.37
this program segment READs the values from the DATA statements into
the array A. After execution, the value of A(1) will be 3.08, and so on.
continued on next page
6-202 GW-BASIC Reference Manual
reads string and numeric data from the DATA statement in line 30 and
yields:
REM STATEMENT
PURPOSE:
Allows explanatory remarks to be inserted in a program.
SYNTAX:
REM [ <remark>]
NOTES:
REM statements are not executed but are output exactly as entered
when the program is listed.
Remarks may be added to the end of a line by preceding the remark with
a single quotation mark (') instead of :REM.
EXAMPLES:
or:
RENUM COMMAND
PURPOSE:
Renumbers program lines.
SYNTAX:
RENUM [[ <new number>][. [<old number>][, <increment> III
NOTES:
<new number> is the first line number to be used in the new sequence.
The default is 10. <old number> is the line in the current program where
renumbering is to begin. The default is the first line of the program.
<increment> is the increment to be used in the new sequence. The
default is 10.
EXAMPLES:
RENUM
Renumbers the entire program. The first new line number will be 10.
Lines will be numbered in increments of 10.
Renumbers the entire program. The first new line number will be 300.
Lines will be numbered in increments of 50.
RENUM 1000,900,20
Renumbers the lines from 900 up, starting with line number 1000 and
proceeding in increments of 20.
Commands, Statements, Functions, and Variables 6-205
RESET COMMAND
PURPOSE:
Closes all files on all drives and RAM cartridges.
SYNTAX:
RESET
NOTES:
RESET closes all open files on all drives and RAM cartridges and writes
the directory track to every disk with open files.
All files must be closed before a disk is removed from its drive.
EXAMPLE:
RESET
6-206 GW-BASIC Reference Manual
RESTORE STATEMENT
PURPOSE:
Allows DATA statements to be reread from a specified line.
SYNTAX:
RESTORE [<line number>]
NOTES:
After a RESTORE statement is executed, the next READ statement
accesses the first item in the first DATA statement in the program. If
<line number> is specified, the next READ statement accesses the first
item in the specified DATA statement.
EXAMPLE:
10 READ A,B,C
20 RESTORE
30 READ D,E,F
40 DATA 57, 68, 79
50 PRINT A;B;C;D;E;F;
RUN
576879576879
Commands, Statements, Functions, and Variables 6-207
RESUME STATEMENT
PURPOSE:
Continues program execution after an error recovery procedure has
been performed.
SYNTAX:
RESUME [0]
RESUME NEXT
NOTES:
Anyone of the syntax forms shown above may be used, depending
upon where execution is to resume:
Syntax Explanation
EXAMPLE:
10 ON ERROR GOTO 900
RETURN STATEMENT
RIGHT$ FUNCTION
PURPOSE:
Returns the rightmost I characters of string X$.
SYNTAX:
Y$ = RIGHT$(X$,I)
NOTES:
If I is greater than or equal to the number of characters in X$ (LEN(X$)),
then RIGHT$(X$,I) returns X$. If I = 0, the null string (length zero) is
returned.
Also see the LEFT$ and MID$ functions described earlier in this section.
EXAMPLE:
The function:
will yield:
BASIC
6-210 GW-BASIC Reference Manual
RMDIR STATEMENT
PURPOSE:
Removes a directory from the MS-DOS file system.
SYNTAX:
RMDIR <pathname>
NOTES:
RMDIR works exactly like the MS-DOS command RMDIR.
EXAMPLES:
Assume that the current directory is \SALES\JOHN:
or:
RMDIR "..\..\INVENTORY"
Possible Errors:
The subdirectory to be deleted must be empty of all files except '.' and
'.. '; otherwise, a "Path not found" error is given.
Commands, Statements, Functions, and Variables 6-211
RND FUNCTION
PURPOSE:
Returns a random number between 0 and 1.
SYNTAX:
Y = RND[(X)]
NOTES:
The same sequence of random numbers is generated each time the
program is run unless the random number generator is reseeded (see
"RANDOMIZE Statement" earlier in this section).
X <0 always restarts the same sequence for any given X. X> 0 or X
omitted generates the next random number in the sequence. X = 0
repeats the last number generated.
EXAMPLE:
The function:
10 FOR 1=1 TO 5
20 PRINT INT(RND*100);
30 NEXT
could yield:
243031515
6-212 GW-BASIC Reference Manual
RUN COMMAND
PURPOSE:
Executes the program currently in memory (see Syntax 1). Also loads a
file from disk into memory and runs the file (see Syntax 2).
SYNTAX 1:
RUN [<line number>]
SYNTAX 2:
RUN <filespec>[,R]
NOTES:
Execution of the RUN command automatically cancels the definitions of
all animation objects.
For Syntax 2, the <filespec> must include the filename used when the
file was saved. (GW-BASIC appends a default filename extension of
.BAS if one was not supplied in the SAVE command.)
This version of 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.
EXAMPLES:
RUN
RUN "NEWFIL",R
Commands, Statements, Functions, and Variables 6-213
SAVE COMMAND
PURPOSE:
Saves a program file onto a disk or RAM cartridge.
SYNTAX:
SAVE <filespec>[{,A I,P}]
NOTES:
<filespec> is a quoted string that conforms to your operating system's
requirements for filenames. GW-BASIC appends a default filename
extension of .BAS if one is not supplied in the SAVE command. If a
filename already exists, the existing file will be written over.
The A option saves the file in ASCII format. If the A option is not
specified, GW-BASIC saves the file in a compressed binary format.
ASCII format takes more space on the disk, but some disk access
requires that files be in ASCII format. For instance, the MERGE com-
mand (described earlier in this section) requires an ASCII format file,
and some operating system commands such as LIST may also require
an ASCII format file.
EXAMPLES:
The statement:
SAVE "COM2",A
SAVE "PROG",P
SCREEN STATEMENT
PURPOSE:
Selects text mode or one of the 7 graphics modes, enables or disables
color operation, selects the active page for screen operations, and
selects the page to be displayed on the screen.
SYNTAX:
SCREEN [<mode> 1 [,[ <burst> ][,[ <active page>][, <visible
page> III
<active page> selects the active page for text output operations.
NOTES:
The Mindset Personal Computer supports 8 screen modes. <mode> is
a numeric expression which evaluates to an integer in the range 1 to 8.
The characteristics of each screen mode are shown in Table 6-4.
0 Text 2 single/double no
1 320 x 200 4 single/double no
2 640 x 200 2 single/double no
3 320 x 200 2 single/double no
4 320 x 200 16 single no
5 640 x 200 4 single no
6 320 x 400 4 single yes
7 640 x 400 2 single yes
When the SCREEN statement changes the screen mode, it erases the
screen. If the user changes SCREEN values of parameters other than
mode, the screen is not erased.
EXAMPLES:
The statement:
10 SCREEN 0,0
10 SCREEN ",1
10 SCREEN 4,1
SCREEN FUNCTION
PURPOSE:
Reads a character or its color from a specified screen location.
SYNTAX:
Y = SCREEN«row>,<column>[,X])
NOTES:
The ordinate of the character at the specified coordinates is stored in the
numeric variable. If the optional parameter X is given and is non-zero, .
the color attribute for the character is returned instead.
EXAMPLES:
In the function:
returns the color attribute of the character in the upper left corner of the
screen.
Commands, Statements, Functions, and Variables 6-217
SGN FUNCTION
PURPOSE:
Indicates the value of X, relative to zero:
SYNTAX:
Y = SGN(X)
EXAMPLE:
The function:
SHELL STATEMENT
PURPOSE:
Loads and executes another program (.EXE or .COM). When the
program finishes, control returns to the BASIC program at the statement
following the SHELL statement. A program executed under control of
BASIC is referred to as a "Child process".
Child processes (or "children") are executed when SHELL loads and
runs a copy of COMMAND with the "/C "switch. By using COMMAND
in this way, parameters are correctly parsed into the default FCBs, and
built-in MS-DOS commands such as DIR, PATH, and SORT may be
executed.
SYNTAX:
SHELL [<command string> 1
NOTES:
The following rules apply to the SHELL statement:
2. Any text separated from the program name by at least one blank will
be processed by COMMAND as one or more program parameters.
3. SHELL works just like the XENIX command 'SH'. That is, BASIC
remains in memory while the Child process is running. When the child
finishes, BASIC continues.
4. You cannot SHELL to another copy of BASIC. When the user attempts
to run BASIC as a Child process, BASIC recognizes the situation
before initialization and returns to the Parent copy of BASIC after
issuing the message: "You cannot run BASIC as a child of BASIC".
This restriction is provided as an implementation option for cases
where it is necessary to protect the integrity of the BASIC Parent
program.
Child Processes
BASIC cannot totally protect itself from its children. When a SHELL
statement is executed, many things may already be going on. For
example, files may already be OPEN and devices may be in use. The
following guidelines will help to prevent Child processes from harming
the BASIC environment.
1. Hardware considerations:
A child that alters any file open in the BASIC parent may cause
disastrous results.
3. Memory Management:
Unless BASIC is started with the 1M: switch, it will try to free any
memory it is not using before it passes control through the SHELL
statement to COMMAND.
With the 1M: switch, BASIC must assume that the user intends to load
something in the top of BASIC's Memory Block. This assumption
prevents BASIC from "compressing the workspace" before doing the
SHELL. Consequently, use of the 1M: switch may cause SHELL to fail
on an "Out of memory" error.
CSEG ENDS
END START
A child should NEVER "terminate and stay resident". Doing so may not
leave BASIC enough room to expand its workspace to the original size.
If BASIC cannot restore the workspace, all files are closed, the error
message "SHELL can't continue" is printed, and BASIC exits to
MS-DOS.
EXAMPLES:
SHELL 'get a new COMMAND
A>DIR {user types DIR to see files}
A>EXIT {user types EXIT to return to BASIC}
The user writes some data to be sorted, invokes the SHELL sort to sort it,
then reads the sorted data to write a report:
1000 CLOSE 1
101 0 SHELL "SORT <SORTINDAT >SORTOUT.DAT"
1020 OPEN "SORTOUT.DAT" FOR INPUT AS #1
SIN FUNCTION
PURPOSE:
Returns the sine of X, where X is in radians.
SYNTAX:
Y = SIN(X)
NOTES:
COS(X) = SIN(X+3.14159/2).
EXAMPLE:
The function:
PRINT SIN(1.5)
will yield:
.9974951
SOUND STATEMENT
PURPOSE:
Generates a sound through the speaker.
SYNTAX:
SOU ND <freq >, < duration> [, <vol ume > [, <voice> ]]
<duration> is the duration in clock ticks. Clock ticks occur 18.2 times
per second. <duration> must be a numeric expression returning an
unsigned integer in the range 0 to 65535.
<volume> uses a value from 0 to 255 to set the volume for the note. The
default value of 255 produces the loudest sound.
<voice> selects one of four voices to play the note. The range of
<voice> is 0 to 3. Voice 0 is the default.
NOTES:
If the duration is zero, any SOUND statement currently running will be
turned off. If no SOUND statement is currently running, a SOUND
statement with a duration of zero will have no effect.
EXAMPLE:
30 SOUND RND* 1000+37,2
SPACES FUNCTION
PURPOSE:
Returns a string of spaces of length X.
SYNTAX:
Y$ = SPACE$(X)
NOTES:
The expression X is rounded to an integer and must be in the range
oto 255.
EXAMPLE:
The function:
10 FOR I = 1 TO 5
20 X$ = SPACE$(I)
30 PRINT X$;I
40 NEXT I
will yield:
2
3
4
5
6-224 GW-BASIC Reference Manual
SPC FUNCTION
PURPOSE:
Skips spaces in a PRINT statement. I is the number of spaces to be
skipped.
SYNTAX:
PRINT... SPC(I) .. .
LPRI NT. .. SPC(I) .. .
NOTES:
SPC may be used only with PRINT and LPRINT statements. I must be in
the range 0 to 255. A semicolon (;) is assumed to follow the string of
spaces printed by the SPC(I) command.
EXAMPLE:
The function:
will yield:
OVER THERE
Commands, Statements, Functions, and Variables 6-225
SQR FUNCTION
PURPOSE:
Returns the square root of X.
SYNTAX:
Y = SOR(X)
NOTES:
X must be > = O.
EXAMPLE:
The function:
10 FOR X = 10 TO 25 STEP 5
20 PRINT X, SOR(X)
30 NEXT
will yield:
10 3.162278
15 3.872984
20 4.472136
25 5
6-226 GW-BASIC Reference Manual
STICK FUNCTION
PURPOSE:
Returns the X and Y coordinates of the two joysticks.
SYNTAX:
X = STICK(I)
NOTES:
The values for I can be:
Value Explanation
The coordinate data for a mouse is not scaled in any way; it represents
the number of pulses received from the mouse, The user must scale this
data to represent screen coordinates, and the scaling factor will vary
according to the size of each individual screen.
Commands, Statements, Functions, and Variables 6-227
EXAMPLES:
The following routine:
10 CLS
20 LOCATE 1 ,1
30 PRINT "X = ";STICK(O)
40 PRINT "Y = ";STICK(1)
50 GOTO 20
STOP STATEMENT
PURPOSE:
Terminates program execution and returns to command level.
SYNTAX:
STOP
NOTES:
STOP statements may be used anywhere in a program to terminate
execution. STOP is often used for debugging. When a STOP is
encountered, the following message is printed:
EXAMPLE:
The function:
10 INPUT A,B,C
20 K=AI\2*5.3:L= B;\3/.26
30 STOP
40 M=C*K+100:PRINT M
will yield:
? 1,2,3
BREAK IN 30
PRINT L
30.76923
CaNT
115.9
Commands, Statements, Functions, and Variables 6-229
PURPOSE:
STOP OBJECT halts the motion and freezes the current view of one or
more objects on the screen. START OBJECT restarts one or more
objects which have been halted with a STOP OBJECT statement.
SYNTAX:
START OBJECT [<object number>[, <object number> ... ]]
STOP OBJECT [<object number>[,<object number> ... ]]
NOTES:
The STOP OBJECT statement freezes the specified object(s) on the
screen but does not erase them, as does the DEACTIVATE statement.
The START OBJECT statement unfreezes the specified object(s) after
they have been stopped by a STOP OBJECT statement.
EXAMPLES:
The statement:
20 START OBJECT 1
STR$ FUNCTION
PURPOSE:
Returns a string representation of the value of X.
SYNTAX:
Y$ = STR$(X)
NOTES:
Also see "VAL Function".
EXAMPLE:
5 REM ARITHMETIC FOR KIDS
10 INPUT "TYPE A NUMBER";N
20 ON LEN(STR$(N)) GOSUB 30,100,200,300,400,500
Commands, Statements, Functions, and Variables 6-231
STRIG STATEMENT/FUNCTION
PURPOSE:
The STRIG ON statement enables event trapping of joystick or mouse
switch activity.
SYNTAX:
STRIG ON
STRIG OFF
STRIG STOP
X = STRIG(I)
NOTES:
The STRIG ON statement enables joystick/mouse event trapping by an
ON STRIG statement (see "ON STRIG Statement" earlier in this section).
While trapping is enabled, if a non-zero line number is specified in the
ON STRIG statement, GW-BASIC checks between every statement to
see if the joystick trigger or mouse switch has been pressed.
Value Explanation
EXAMPLE:
In the following routine:
STRING$ FUNCTION
PURPOSE:
Returns a string of length I whose characters all have ASCII code J or
the first character of X$.
SYNTAX:
Y$ = STRING$(I,J)
Y$ = STRING$(I,X$)
EXAMPLE:
The function:
10 X$ =STRING$(10,45)
20 PRINT X$ "MONTHLY REPORT" X$
will yield:
----------MONTHLY REPORT----------
6-234 GW-BASIC Reference Manual
SWAP STATEMENT
PURPOSE:
Exchanges the values ot two variables.
SYNTAX:
SWAP <variable>, <variable>
NOTES:
Variables of any type (integer, single precision, double precision, or
string) may be swapped, but the two variables must be of the same type
or a "Type mismatch" error results.
EXAMPLE:
The routine:
will yield:
SYSTEM COMMAND
PURPOSE:
Closes all open files, disables animation, and returns control to the
operating system.
SYNTAX:
SYSTEM
NOTES:
When a SYSTEM command is executed, a "warm start" is performed (in
other words, all open files are closed, and the operating system is
reloaded without deleting any existing programs or memory except
GW-BASIC itself).
TAB FUNCTION
PURPOSE:
Moves the print position to I.
SYNTAX:
PRINT... TAB(I) .. .
LPRINT... TAB(I) .. .
NOTES:
If the current print position is already beyond space I, TAB goes to that
position on the next line.
Space 1 is the leftmost position, and the rightmost position is the width
minus one. I must be in the range 1 to 255.
EXAMPLE:
The function:
will yield:
NAME AMOUNT
G. T. JONES $25.00
Commands, Statements, Functions, and Variables 6-237
TAN FUNCTION
PURPOSE:
Returns the tangent of X. X should be given in radians.
SYNTAX:
Y = TAN(X)
NOTES:
If TAN overflows, the "Overflow" error message is displayed, machine
infinity with the appropriate sign is supplied as the result, and execution
continues.
EXAMPLE:
10 Y = Q*TAN(X)/2
6-238 GW-BASIC Reference Manual
TIME$ STATEMENT
PURPOSE:
Sets the time. This statement complements the TIME$ variable, which
retrieves the time.
SYNTAX:
TIME$ = <string expression>
NOTES:
A 24-hour clock is used; 8:00 p.m., therefore, would be entered as
20:00:00.
EXAMPLE:
The statement:
10 TIME$ = "08:00:00"
TIME$ VARIABLE
PURPOSE:
Retrieves the current time. (To set the time, use the TIME$ statement,
described earlier in this section.)
NOTES:
The TIME$ variable returns an eight-character string in the form
hh:mm:ss, where hh is the hour (00 through 23), mm is minutes (00
through 59), and ss is seconds (00 through 59). A 24-hour clock is used;
8:00 p.m., therefore, would be shown as 20:00:00.
The time is set by a BASIC program with the TIME$ statement or by the
operating system.
EXAMPLE:
At 1:00 a.m., the function:
10 PRINT TIME$
will yield:
01:00:00
6-240 GW-BASIC Reference Manual
TIMER VARIABLE
PURPOSE:
Returns a floating-point number representing the elapsed number of
seconds either since midnight or since a system reset.
NOTES:
TIMER is a read-only variable. It cannot be set by a BASIC program.
The TIMER variable can automatically provide a random seed for the
RANDOMIZE statement (see "RANDOMIZE Statement" earlier in this
section).
EXAMPLE:
The program:
10 T=TIMER
20 INPUT "Enter a character", A$
30 PRINT TIMER - T;"seconds."
prints the number of seconds from the start of program execution to the
pressing of the RETURN key after a character is entered.
Commands, Statements, Functions, and Variables 6-241
TRONITROFF STATEMENTS/COMMANDS
PURPOSE:
Traces the execution of program statements.
SYNTAX:
TRON
TROFF
NOTES:
As an aid in debugging, the TRON statement (executed in either direct
or indirect mode) enables a trace flag that prints each line number of the
program as it is executed. The numbers appear enclosed in square
brackets.
The trace flag is disabled with the TROFF statement (or when a NEW
command is executed).
EXAMPLE:
The routine:
TRON
10 K=10
20 FOR J=1 TO 2
30 L= K + 10
40 PRINT J;K;L
50 K=K+10
60 NEXT
70 END
RUN
will yield:
TROFF
RUN
1 1020
22030
6-242 GW-BASIC Reference Manual
USR FUNCTION
PURPOSE:
Calls an assembly language subroutine.
SYNTAX:
X = USR[<digit>][«argument»]
<digit> specifies which USR routine is being called. See the DEF USR
statement earlier in this section for rules governing <digit>. If <digit>
is omitted, USRO is assumed.
NOTES:
If a segment other than the default segment (data segment OS) is to be
used, a DEF SEG statement must be executed prior to a USR function
call. The address given in the DEF SEG statement determines the
segment address of the subroutine.
EXAMPLE:
In the following use of the USR function:
the type (numeric or string) of the variable receiving the function call
must be consistent with the argument passed.
Commands, Statements, Functions, and Variables 6-243
VAL FUNCTION
PURPOSE:
Returns the numerical value of string X$. The VAL function also strips
leading blanks, tabs, and linefeeds from the argument string. For
example, VAL(" - 3") returns - 3.
SYNTAX:
Y = VAL(X$)
EXAMPLE:
10 READ NAME$,CITY$,STATE$,ZIP$
20 IF VAL(ZIP$)<90000 OR VAL(ZIP$»96699
THEN PRINT NAME$ TAB(25) "OUT OF STATE"
30 IF VAL(ZIP$» =90801 AND VAL(ZIP$)< =90815
THEN PRINT NAME$ TAB(25) "LONG BEACH"
VARPTR FUNCTION
PURPOSE:
Returns the address of the first byte of data identified with
<variable name>.
For sequential files, returns the starting address of the disk I/O buffer
assigned to <file number>. For random files, returns the address of the
FIELD buffer assigned to <file number>. (See Syntax 2.)
SYNTAX 1:
I = VARPTR( <variable name»
SYNTAX 2:
I = VARPTR(#<file number»
NOTES:
A value must be assigned to <variable name> before execution of
VARPTR. Otherwise an "Illegal function call" error results. A variable of
any type may be used (numeric, string, array). For string variables, the
address of the first byte of the string descriptor is returned (see
':Assembly Language Subroutines" in Section 2 for a discussion of the
string descriptor). The address returned will be an integer in the range
32767 to - 32768. If a negative address is returned, add it to 65536 to
obtain the actual address.
Note: All simple variables should be assigned before calling VARPTR for
an array, because the addresses of the arrays change whenever a new
simple variable is assigned.
EXAMPLE:
100 X= USR(VARPTR(Y))
Commands, Statements, Functions, and Variables 6-245
VARPTR$ FUNCTION
PURPOSE:
Returns a character form of the memory address of the variable.
SYNTAX:
X$ = VARPTR$( <variable name»
NOTES:
VARPTR$ is primarily used with the DRAW and PLAY statements.
byte 0 = type
byte 1 = low byte of address
byte 2 = high byte of address
Note, however, that the individual parts of the string are not considered
characters.
2 Integer
3 String
4 Single precision
8 Double precision
EXAMPLE:
The function:
10 PLAY "XA$;"
Commands, Statements, Functions, and Variables 6-247
VIEW STATEMENT
PURPOSE:
Segments the screen into separate viewports for graphics operations.
SYNTAX:
VIEW [[SCREEN][(X1 ,Y1) - (X2,Y2)[,[ <fill>][,[ <border>]]]]]
(X1 ,Y1) are the screen coordinates of the upper left corner of the
viewport and (X2,Y2) are the screen coordinates of the lower right
corner. The X and Y coordinates define the rectangle within the screen
that graphics will map into; they must be within the physical bounds of
the screen.
Initially, RUN or VIEW with no arguments defines the entire screen as the
viewport.
<fill> defines the color to fill the view area. If <fill> is omitted, the view
area is not filled.
NOTES:
For the form VIEW (X1,Y1)-(X2,Y2): All points plotted are relative to the
viewport. That is, X1 and Y1 are added to the X and Y coordinates before
putting down the point on the screen.
For the form VIEW SCREEN (X1 ,Y1) - (X2,Y2): All coordinates are
absolute and may be inside or outside the screen limits; however, only
those coordinates within the VIEW limits will be plotted.
EXAMPLES:
The statement:
The statement:
PURPOSE:
Sets the top and bottom boundaries of the text window.
SYNTAX:
VIEW PRINT [<top line> TO <bottom line>]
<top line> is the top boundary and <bottom line> is the bottom
boundary of the text window. The range of these parameters is from 1 to
25.
NOTES:
Statements and functions which operate within the text window include
CLS, LOCATE, and the SCREEN function. The Screen Editor will limit
functions such as scroll and cursor movement to the text window.
If no parameters are specified, VIEW PRINT will initialize the text window
to include the whole screen.
EXAMPLE:
The statement:
10 VIEW PRINT 3 to 13
sets the text window to include the 11 lines from line 3 to line 13.
Commands, Statements, Functions, and Variables 6-249
WAIT STATEMENT
PURPOSE:
Suspends program execution while monitoring the status of a machine
input port.
SYNTAX:
WAIT <port number>,I[,J]
NOTES:
The WAIT statement causes program execution to be suspended until a
specified machine input port develops a specified bit pattern. The data
read at the port is exclusive OR'ed with the integer expression J, and
then ANO'ed with I. If the result is zero, GW-BASIC loops back and
reads the data at the port again. If the result is non-zero, program
execution continues with the next statement. If J is omitted, its value is
assumed to be zero.
EXAMPLE:
The statement:
PURPOSE:
Executes a series of statements in a loop as long as a given condition is
true.
SYNTAX:
WHILE <expression>
[<loop statements> 1
WEND
NOTES:
If <expression> is not zero (in other words, if the expression is true),
<loop statements> are executed until the WEND statement is encoun-
tered. GW-BASIC then returns to the WHILE statement and checks
<expression> again. If it is still true, the process is repeated. If it is not
true, execution resumes with the statement following the WEND
statement.
WHILE/WEND loops may be nested to any level. Each WEND will match
the most recent WHILE. An unmatched WHILE statement causes a
"WHILE without WEND" error, and an unmatched WEND statement
causes a "WEND without WHILE" error.
EXAMPLE:
100 'BUBBLE SORT ARRAY A$
105 FLlPS= 1 'FORCE ONE PASS THRU LOOP
110 WHILE FLIPS
115 FLlPS=O
120 FOR 1=1 TO J-1
130 IF A$(I»A$(I + 1) THEN SWAP A$(I),A$(I + 1):FLlPS = 1
140 NEXT I
150 WEND
Commands, Statements, Functions, and Variables 6-251
WIDTH STATEMENT
PURPOSE:
Sets the printed line width in number of characters for the screen or line
printer.
SYNTAX 1:
WIDTH [LPRINT ]<size>
SYNTAX 2:
WIDTH <file number>,<size>
SYNTAX 3:
WIDTH <device>,<size>
NOTES:
With Syntax 1, if LPRINT is included, the line width is set for the line
printer width. If the LPRINT option is omitted, the line width is set for the
screen display. The <size> value in this case must be 40 or 80.
GW-BASIC clears the screen when it changes the width from 40 to 80 or
from 80 to 40.
With Syntax 2, if the file is open to the line printer, the width is immedi-
ately changed to the specified size. This feature allows the width to be
changed while the file is open.
EXAMPLE:
10 PRINT 'I\BCDEFGHIJKLMNOPQRSTUVWXYZ"
RUN
ABCDEFGH IJ KLMNOPQRSTUVWXYZ
Ok
WIDTH 18
Ok
RUN
ABCDEFGH IJKLMNOPQR
STUVWXYZ
Ok
Commands, Statements, Functions, and Variables 6-253
WINDOW STATEMENT
PURPOSE:
WINDOW enables you to draw lines, graphs, or objects in a coordinate
system not bounded by the physical limits of the screen. Such drawing
is done by using arbitrary programmer-defined coordinates called
"world coordinates".
SYNTAX:
WINDOW [[SCREEN](Xi ,Yi) - (X2,Y2)]
NOTES:
WINDOW inverts the Y coordinate on subsequent graphics statements.
This inversion enables the screen to be viewed in true cartesian
coordinates.
EXAMPLES:
The following program:
10 NEW
20 SCREEN 2
1 y increases
320,100
t y increases
0,0
+y decreases
-1, -1 0, -1 1, -1
-1, -1 0, -1 1, -1
t y decreases
0,0
y increases
-1,1
+ 0,1 1,1
Commands, Statements, Functions, and Variables 6-255
WRITE STATEMENT
PURPOSE:
Displays data on the screen.
SYNTAX:
WRITE [<list of expressions> 1
NOTES:
If <list of expressions> is omitted, a blank line is displayed. If <list of
expressions> is included, the values of the expressions are shown on
the screen. The expressions in the list may be numeric and/or string
expressions. They must be separated by commas.
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, GW-BASIC inserts a carriage return/
linefeed.
WRITE outputs numeric values using the same format as the PRINT
statement.
EXAMPLE:
The routine:
will yield:
WRITE # STATEMENT
PURPOSE:
Writes data to a sequential file.
SYNTAX:
WRITE # <file number>,<list of expressions>
NOTES:
<file number> is the number under which the file was OPENed in "0"
mode (see "OPEN Statement" in this section).
EXAMPLE:
If A$ = "CAMERA" and B$ = "93604 -1", the statement:
WRITE #1,A$,B$
INPUT #1 ,A$,B$
The ON ERROR GOTO statement can be used to trap the errors before
GW-BASIC prints an error message. In this case, the ERR variable
contains the number of the error and ERL contains the number of the line
which caused the error.
2 Syntax error
A-1
A-2 GW-BASIC Reference Manual
4 Out of data
6 Overflow
7 Out of memory
8 Undefined line
10 Duplicate definition
Two DIM statements are given for the same array; or, a DIM
statement is given for an array after the default dimension of 10
has been established for that a,rray.
11 Division by zero
12 Illegal direct
13 Type mismatch
17 Can't continue
19 No RESUME
21 Unprintable error
22 Missing operand
An attempt has been made to enter a line that has too many
characters.
24 Device timeout
25 Device fault
27 Out of paper
28 Unprintable error
50 Field overflow
51 Internal error
56 Unprintable error
61 Disk full
64 Bad filename
65 Unprintable error
68 Device unavailable
Derived Mathematical
Functions
B-1
B-2 GW-BASIC Reference Manual
INVERSE HYPERBOLIC
SECANT ARCSECH(X) = LOG((SQR( - X*X + 1) + 1)/X)
INVERSE HYPERBOLIC
COSECANT ARCCSCH(X) = LOG((SGN(X)
*SQR(X*X + 1) + 1)/X)
INVERSE HYPERBOLIC
COTANGENT ARCCOTH(X) = LOG((X + 1)/(X -1 ))/2
Appendix C
C-1
C-2 GW-BASIC Reference Manual
Extended Codes
3 NUL 66 F8
character 67 F9
15 SHIFT-TAB 68 F10
16 ALT-Q 71 HOME
17
18
19
ALT-W
ALT-E
ALT-R
72
73
75
•.....
PG UP
20 ALT-T 77 ~
21 ALT-Y 79 END
22
23
24
ALT-U
ALT-I
ALT-O
80
81
82
•
PG ON
INS
25 ALT-P 83 DEL
30 ALT-A 84 SHIFT-F1
31 ALT-S 85 SHIFT-F2
32 ALT-D 86 SHIFT-F3
33 ALT-F 87 SHIFT-F4
34 ALT-G 88 SHIFT-F5
35 ALT-H 89 SHIFT-F6
36 ALT-J 90 SHIFT-F7
37 ALT-K 91 SHIFT-F8
38 ALT-L 92 SHIFT-F9
44 ALT-Z 93 SHIFT-F10
45 ALT-X 94 CTRL-F1
46 ALT-C 95 CTRL-F2
47 ALT-V 96 CTRL-F3
48 ALT-B 97 CTRL-F4
49 ALT-N 98 CTRL-F5
50 ALT-M 99 CTRL-F6
59 F1 100 CTRL-F7
60 F2 101 CTRL-F8
61 F3 102 CTRL-F9
62 F4 103 CTRL-F10
63 F5 104 ALT-F1
64 F6 105 ALT-F2
65 F7 105 ALT-F3
Note: The extended codes 59 through 68 are available only when the
corresponding function keys are not defined as soft keys.
AppendixD
GW-BASIC Reserved
Words
ABS DATE$
ACTIVATE DEACTIVATE
AND DEFDBL
ASC DEFINT
ARRIVAL DEFSNG
ATN DEFSTR
AUTO DEFFN
BEEP DEF OBJECT
BLOAD DEF USR
BSAVE DELETE
CALL DIM
CDBL DRAW
CHAIN EDIT
CHDIR ELSE
CHR$ END
CINT ENVIRON
CIRCLE ENVIRON$
CLEAR EOF
CLIP ERASE
CLOSE ERDEV
CLS ERDEV$
COLLISION ERL
COLOR ERR
COM ERROR
COMMON END
CO NT EXP
COS FIELD
CSNG FILES
CVD FIX
CVI FOR
CVS FRE
DATA
D-1
0-2 GW-BASIC Reference Manual
GET PAINT
GOSUB PALETTE
HEX$ PALETTE USING
IF PEEK
IMP PEN
INKEY$ PLAY
INP PMAP
INPUT POINT
INPUT# POKE
INPUT$ POS
INSTR PRESET
INT PRINT
IOCTL PRINT USING
IOCTL$ PRINT #
KEY PRINT # USING
KILL PSET
LEFT$ PUT
LEN RANDOMIZE
LET READ
LINE REM
LIST RENUM
LLiST RESET
LOAD RESTORE
LOC RESUME
LOCATE RIGHT$
LOF RMDIR
LOG RND
LPOS RSET
LPRINT RUN
LSET SAVE
MERGE SCREEN
MID$ SGN
MKD$ Sf:lELL
MKDIR SIN
MKI$ SOUND
MKS$ SPACE
MOD SPC
NAME SQR
NEW START
NEXT STICK
NOT STOP
OBJECT STR$
OCT$ STRIG
ON STRING$
OPEN SWAP
OPEN COM SYSTEM
OPTION TAB
OR TAN
GW-BASIC Reserved Words D-3
THEN VARPTR$
TIME$ VIEW
TIMER WAIT
TO WEND
TROFF WHILE
TRON WIDTH
USING WINDOW
USR WRITE
VAL WRITE#
VARPTR XOR
Index
~key, 5-5
CTRL-~, 5-4
~ key, 5-5
CTRL-~, 5-4
• key, 5-5
.. key, 5-5
1-1
1-2 GW-BASIC Reference Manual
Graphics, 1-1
Color figure, 6-166
Modes, 6-214
Graphics Macro Language (GML), 6-59
Line
Continuation, 2-2
Editing, 5-1
Format, 2-2
Length, 2-2, 5-3
Multiple statements, 2-2
Number generation, 6-12
Numbers, 2-2, 6-204
Printer, 5-121,6-128
Linefeed, 5-2, 6-96, 6-117
Writing statements, 6-255
Linefeed (editor function), 5-5
Linefeed key, 2-2
LINE INPUT statement, 5-6,6-117
LINE INPUT# statement, 6-118
LINE statement, 6-114
LIST command, 2-2, 5-3, 6-119
LLiST command, 6-121
LOAD command, 6-122
LOCATE statement, 6-124
LOC function, 6-123
LOF function, 6-126
LOG function, 6-127
Logical line, 2-2
Definition with INPUT, 5-6
Logical operators, 2-14
Loops, 6-81, 6-249
LPOS function, 6-128, 6-251
LPRINT statement, 6-129, 6-251
LPRINT USING statement, 6-129
LSET statement, 6-130
Remarks, 6-203
REM statement, 6-203
RENUM command, 6-19, 6-71, 6-204
Reserved words, 0-1
RESET command, 6-205
RESTORE statement, 6-201, 6-206
RESUME statement, 6-207
RETURN, event trapping, 1-6
RETURN key, 2-4
Editing, 5-3, 5-5
RETURN statement, 6-88, 6-208
RIGHT$ function, 6-209
RMDIR statement, 6-210
RND function, 6-199, 6-211
RSET statement, 6-130
RUN command, 6-212
Runtime error messages, A-1
Version 1. 01
Updat~
Please add these pages to the binder containing your GW-BASIC Reference
Hanua1. It's a good idea to review the changes and additions listed
here before you begin using GW-BASIC, even if you're unfamiliar with
GW-BASIC programming and may not understand all the terms and details
discussed.
Each item is listed by topic and, with a few exceptions, by page reference
to the GW-BASIC Reference t1anua1. You may wish to note some of these
changes and additions on the appropriate pages of your manuals.
SHIFT-PRT SCN and If you press SHIFT-PRT SCN to copy the text
GW-BASIC on your screen to a printer (see your Mindset
Operation Guide, page 3-3) while using
GW-BASIC, the last character in some lines
may not be printed.
Sound and music All the sound and music functions and statements
functions in GW-BASIC, including BEEP (see page 6-13) and
CHR$(7) (the BELL character--see page 6-23),
1-2 produce sound only if your Mindset Personal
Computer is connected to an external amplifier
and speaker system through the AUDIO LEFT con-
nector on the back of the System Unit.
1-7
GW-BASIC Update 2
Version 1.01
Hex Decimal
Code Code Key Function
03 03 C Break
05 05 E Truncate line (clear text to end of logical line on
screen and in memory)
07 07 G Beep
08 08 H Backspace, deleting characters passed over
09 09 I Tab (8 spaces)
OA 10 J Linefeed
OB 11 K Move cursor to home position
OC 12 L Clear window
OD 13 M Carriage return (enter current logical line)
OE 14 N Append to end of line
12 18 R Toggle insert/typeover mode
14 20 T Display function key contents
15 21 U Clear logical line (on screen only)
17 23 W Delete word
lA 26 Z Clear to end of window (on screen only)
lC 28 \ Cursor right
lD 29 ] Cursor left
IE 30 '" Cursor up
IF 31 Cursor down (underscore)
7F 127 DEL Delete character at cursor--functions without the
CTRL key having to be pressed
OPEN and line printer You cannot send output to a line printer with
operation the statement OPEN "LPTn"--a "Bad file mode"
error message will result.
6-160
GW-BASIC Update 3
Version 1. 01
VIEW--fill and border When used with a fill parameter. the optional
parameters border parame,ter will not result in the
drawing ofa\>order.
6-247
WIDTH and line SYNTAX 2. WIDTH (file number>. (size>. will not
printer operation work with a line printer.
6-251
Before you make your backup copy, you may also wish to add to at least one
of your original program diskettes some DOS files that will enable youito
boot up your computer system and run GW-BASIC using the same diskette--
that is, without first having to load MST~DOS separately.
Space has been reserved on your GW-BASIC program diskettes 'for MS-DOS
system and COMMAND.COM files. Added to a program diskette, these files
enable you to boot up your computer system, then run GW-BASIC using only
your GW-BASIC program diskette--that is, without first having to load
MS-DOS separately.
To add these files to a GW-BASIC program diskette, first load MS-DOS into
your system. Be sure that there's no write-protect tab on your GW-BASIC
diskette. With your MS-DOS diskette in drive A and your GW-BASIC diskette
in drive B, type SYS B: and press RETURN. (If you have only one disk
drive, see Appendix A in your MS-DOS Reference Manual.) When the message
"System transferred" appears, the system files have been added to your
GW-BASIC diskette.
Next, type COpy COMMAND.COM B: and press RETURN. When the message "1 File(s)
copied" appears, the COMMAND.COM file has been added to your GW-BASIC
diskette.
(See your MS-DOS Reference Manual for details on the SYS command and the
COMMAND.COM file.)
You may now use your GW-BASIC program diskette to boot up your system, then
run GW-BASIC. If your system is turned off, place the GW-BASIC diskette
in the default drive and turn on the system; if the system is already on,
place the GW-BASIC diskette in the default drive and press ALT-RESET. Next,
when prompted for an entry, type BASIC and press RETURN.
your MS-DOS diskette in drive A and your blank diskette in drive B, type
FORMAT B: and press RETURN. (If you have only one disk drive, see Appendix
A in your MS-DOS Reference Manual.)
Next, use the MS-DOS DISKCOPY command to copy your GW-BASIC program disk-
ette onto your newly formatted diskette. Type DISKCOPY A: B: and press
RETURN, then follow the prompts that appear on your screen.
If you accidentally write over any files on your working GW-BASIC program
diskette, use the MS-DOS DISKCOPY command to copy GW-BASIC back onto your
working diskette either from your other original or from your backup copy.
100463-001