Nematron BASIC Manual
Nematron BASIC Manual
DOC-IWS-280
Revision B
September 1996
Nematron Corporation
5840 Interface Drive
Ann Arbor, Michigan 48103
Phone: 734-214-2000
Fax: 734-994-8074
ii Series 30/40 BASIC Guide
Important Information
Note: This equipment has been tested and found to comply with the limits for a
Class A digital device, pursuant to Part 15 of the FCC Rules. These limits are
designed to provide reasonable protection against harmful interference when the
equipment is operated in a commercial environment. This equipment generates,
uses, and can radiate radio frequency energy and, if not installed and used in
accordance with the instruction manual, may cause harmful interference to radio
communications. Operation of this equipment in a residential area is likely to
cause harmful interference in which case the user will be required to correct the
interference at his own expense.
Electrical Shock Hazard! Do not operate the unit with its back cover removed.
There are hazardous voltages inside. Servicing of the equipment should only be
done by qualified and authorized personnel.
Chapter 6 Service
Changing the Fuse ............................................................................6-1
Memory Write Disable......................................................................6-2
Troubleshooting................................................................................6-3
Chapter 7 Concepts
Command/Run Modes ....................................................................... 7-1
Console.............................................................................................. 7-1
Ports .................................................................................................. 7-1
Statements ......................................................................................... 7-2
Numbers and Constants ..................................................................... 7-2
Variables ........................................................................................... 7-3
Scalar Variables ................................................................... 7-3
Array Variables.................................................................... 7-3
Memory Allocation .............................................................. 7-3
Variable Names.................................................................... 7-4
Floating point Variables ....................................................... 7-4
Integer Variables.................................................................. 7-4
String Variables ................................................................... 7-4
Built-in Variables................................................................. 7-4
Operators and Expressions................................................................. 7-4
Operators ............................................................................. 7-4
Expressions .......................................................................... 7-5
Relational Expressions ......................................................... 7-5
Memory Usage................................................................................... 7-5
Chapter 11 Operators
Precedence........................................................................................11-1
Addition (+) .....................................................................................11-2
Subtraction or negation (–) ...............................................................11-3
Multiplication (*) .............................................................................11-4
Division (/) .......................................................................................11-5
Exponentiation (^)............................................................................11-6
Equal (=) ..........................................................................................11-7
Not equal (<>)..................................................................................11-8
Less than (<) ....................................................................................11-9
Greater than (>).............................................................................. 11-10
Less than or equal to (<=)............................................................... 11-11
Greater than or equal to (>=) .......................................................... 11-12
Chapter 12 Logic
Truth Tables................................................................................... 12-1
AND............................................................................................... 12-2
OR ................................................................................................ 12-3
XOR............................................................................................... 12-4
INV .................................................................................................12-5
INV AND....................................................................................... 12-6
INV OR.......................................................................................... 12-7
INV XOR ....................................................................................... 12-8
Chapter 13 CALLs
CALL 12; clear to the end of the display......................................... 13-2
CALL 13; clear to the end of the line.............................................. 13-2
CALL 30; turn on COM1’s RTS line.............................................. 13-3
CALL 33; turn off COM1’s RTS line ............................................. 13-3
CALL 38; enter the on-line configuration menu ............................. 13-4
CALL 39; enter the monitor ........................................................... 13-4
CALL 40 and 41; return characters in COM1 buffer....................... 13-5
CALL 82; print variable list............................................................ 13-6
Appendices
A. Speed-up Hints .......................................................................... A-1
B. Differences between Series 30/40 BASIC and GW-BASIC..........B-1
C. Memory Map ............................................................................. C-1
D. Reference................................................................................... D-1
Command Summary .......................................................... D-1
Operators ........................................................................... D-6
CALLs............................................................................... D-7
Workstation Key Codes...................................................... D-7
CTRL Characters Sent to Workstation ............................... D-8
Ports .................................................................................. D-8
E. Error Codes.................................................................................E-1
Chapter 1
Getting Started
This guide describes the details of the BASIC language in the Series 30/40
Workstations. To get the most from this guide, you should already be familiar
with the BASIC language.
Symbols
Certain symbols in this guide help make you aware of critical information, as
shown below:
The following table shows the meaning of various symbols used throughout this
guide. Words enclosed in square brackets usually represent keys on the keyboard
as shown in the first example below:
Symbol Refers to
[Enter] Key labeled “Enter” (or “Return”) on the keyboard.
UPPER CASE Words that you type exactly as shown.
[Filename] Name of a screen file entered by the user.
lower case An entry that varies based on your needs.
nnn Number that you enter .
var Variable name of any type, such as “A” or “A$.”
nvar Numeric variable such as “A” or “A%.”
svar String variable, such as A$.
const Constant number, such as “123.45” or “5.”
expr Any expression that returns a value, including simple
variables such as “A” as well as such expressions as
“A/B” or “A$ + B$.”
aexpr Any number, variable, or combination that returns a
numeric value in the range of a floating point number.
iexpr Any number, variable, or combination that returns a
numeric value in the range of an integer number.
rexpr Any number, variable, or combination that returns a 0 or
non-zero value; typically includes a relational operator
such as “<” or “>=.”
sexpr Any string or combination that returns a string.
{} Braces indicate an optional entry.
Screens on your computer are enclosed in boxes as shown in the example below:
NEMATRON CORPORATION
Series 30/40 BASIC
Version 5.50
READY – RAM 1
>
Welcome to V5.50 B
Series 30/40 BASIC
This guide indicates something you are supposed to type by italicizing it: Type
This.
Getting Started 1-3
• PC-compatible with:
Minimum 640K of memory
Floppy disk drive
Hard disk drive with 1.5 megabytes of available space
Serial communications port (COM1)
Monochrome or color monitor
PC system software (DOS 2.0 or later)
• IWS-SETUP-BP-30
One 3 1/4" setup diskette. Contact the factory if you require the setup
program on a 5 1/4" diskette.
Cable to connect your PC's 9-pin serial port to your Series 30/40
Workstation’s COM1 port. If your PC has a 25-pin serial port, a
standard 9 to 25 pin adapter will allow you to use the download
cable.
Chapter 2
This chapter describes how to control the Workstation’s display and how the
keyboard operates.
Display
The Series 30 Workstation displays two lines with 20 characters on each line of
a liquid crystal display (LCD) with LED backlighting. Because of the 100,000
hour half-life of the backlight, the Workstation has no “screen saver” function.
The Series 40 Workstation comes with a vacuum fluorescent display (VFD) with
two lines of 20 characters each.
Character Set The character set on both models includes the entire standard ASCII character
set, but is limited only to U.S. characters and eight programmable characters.
Contrast To adjust the contrast of the display on the IWS-30, rotate the knob on the back
Adjustment of the Workstation.
(IWS-30 only)
Keyboard
The keyboard on the Series 30/40 Workstation is a sealed-membrane type with
stainless steel domes that provide tactile feedback.
Keyboard Faults If the Workstation appears to ignore all key presses, the keyboard may be
faulty. If the Workstation senses any invalid combination of keys pressed
simultaneously, it accepts no further key presses until all keys are released.
This provides some protection against a stuck key.
Keyboard Inserts You can change the key and logo legends by replacing inserts that slide in
behind the keyboard. To replace the inserts, you must first remove the back
cover.
For a modest tooling charge and additional cost per unit, Nematron can provide
custom inserts to meet your needs. As an alternative, you can make your own
inserts according to the following instructions.
2-2 Series 30/40 BASIC Guide
Logo Insert You can install your own logo in place of Nematron’s logo. The drawing on
the to shows the insert, which you must cut as shown; the cross mark would
appear at the center of the window. The drawing on the bottom shows the
window, which indicates the maximum size you can print your logo.
Display and Keyboard 2-3
Top Row Insert The drawing on the top shows how to cut an insert for the top row of keys. The
cross marks indicate the center of each key’s legend. The drawing on the
bottom shows the window for each key, which indicates the maximum size you
can print your legends.
2-4 Series 30/40 BASIC Guide
Bottom Row Insert The drawing on the top shows how to cut an insert for the bottom row of keys.
The cross marks indicate the center of each key’s legend. The drawing on the
bottom shows the window for each key, which indicates the maximum size you
can print your legends.
Chapter 3
Hardware Installation
For information on installing and connecting the Series 30/40 units, refer to the
Series 30/40 Installation Guide (DOC-IWS-271; Rev. C), which is included with
the 30/40 Workstation.
Chapter 4
Software Installation
This chapter describes how to install the software included with IWS-SETUP-30/40 on your
hard disk drive and how to download firmware to your Workstation.
Power-Up Sequence
After you apply power, the Workstation checks for valid firmware memory. If the firmware is
valid, the unit displays its model number and performs a brief self-test that includes memory,
keyboard and display.
To speed up the display of the self-test, press [x]. At the end of the self-test, the unit begins
normal operation, which varies depending on the firmware.
If firmware memory is empty or invalid, the Workstation performs an exhaustive test of the
memory. During this test, which lasts about one minute, the Workstation displays the
following:
At the conclusion of the test, the Workstation displays the following message (if the firmware
appears faulty, the message starts with “Invalid” instead of “Empty”):
Empty firmware;
you must download.
Downloading Firmware
This section describes how to change the firmware in your Series 30/40 Industrial
Workstation. You may have to change your firmware either to change its type or to upgrade
the current version.
Because the unit stores its firmware in “flash” memory, each hardware model supports all three
types of firmware. To change firmware, you simply plug in a PC-compatible and transmit a
firmware file.
4-2 Series 30/40 BASIC Guide
When a new Workstation leaves the Nematron factory, it has the Industrial Terminal firmware
already downloaded. If you want to program your unit in BASIC, then you must download
new firmware.
Required Equipment
In order to download firmware, you must have the following equipment and materials
available:
l One 3 1/2” diskette included in the IWS-SETUP-30/40 package.
l PC-compatible with at least 256K RAM, one serial port, one hard disk drive, and one
floppy disk drive.
l Cable to connect your PC to the Workstation; this is part number CBL-C2, and is
included in the IWS-SETUP-30 package.
Downloading The following instructions describe how to download new firmware to your
Series 30/40 Industrial Workstation. Before you begin, you should ensure
that you have the necessary equipment available.
1. If your new Workstation displays the following screen after completing its power-up
self-test, then proceed to step 2:
First-time power-up!
Download or hit key.
If your Workstation does not display this screen, then you must hold down the [↑] and
[↓] keys simultaneously while powering up the Workstation.
Ready to accept
firmware download.
2. If you have already loaded the IWS-SETUP-BP-30 software onto your hard drive, then
skip to step 4. Otherwise, create a directory on your hard drive for the software and
change the current path to that directory.
For example, if you want the directory to be “IWS” then you would type MD IWS and
press [Enter] to create the directory. Then you would type CD IWS and press [Enter] to
change the current path to that directory.
Software Installation 4-3
3. Insert the diskette labeled IWS-SETUP-BP-30 into your PC’s floppy disk drive and type
Copy a:*.* d:\IWS (d = disk drive where you created the subdirectory\IWS) and press
[Enter]. This copies the files to your hard drive.
4. Connect the download cable between the 9-pin COM1 or COM2 port on your PC and
the COM1 port on your Workstation.
5. Type DOWNLOAD followed by the firmware file you want to download to your PC.
Listed below are your filename choices:
For example, to set up your unit for BASIC, type DOWNLOAD HB.
To download using COM2 on your PC, type -2 before the filename; for example,
DOWNLOAD -2 HB.
As of this guide's publication, the most recent release of DOWNLOAD was version 1.81. The
version number is automatically displayed when you run the program.
4-4 Series 30/40 BASIC Guide
Version Numbers
As of this guide’s publication, the most recent release of BP was version 3.36, and the most
recent release of firmware was version 5.50. If you call Nematron for assistance, you should be
able to provide the version numbers you are using. As of this guide's publication, the most
recent release of DOWNLOAD was version 1.81. The version number is automatically
displayed when you run the program.
To find the version of BP software you have, just look at the top line of the screen:
To find the version of firmware you have, cycle power and watch the display during the power-
up self-test:
BASIC V5.50 B
Model IWS-30/40
Chapter 5
On-Line Configuration
This chapter describes how to access and use the built-in configuration program.
The configuration program allows you to set up the operation of your Workstation. For
example, you can set up the communications parameters for your serial port.
F1-Clock F2-Kbd/Dsp
F3-Comm F4-Utility
Selecting a Menu Item To select an item from a menu, simply press the corresponding function
key.
Selecting Parameters To scroll from selection to selection without changing anything, press [↑]
or [↓]. If you make a change and then press [↑] or [↓], the unit does not
record the change and instead goes to the previous or next selection.
Changing Parameters To change a parameter, you must press [+] or [–] to choose the desired
parameter, and then press [↵ ]; the system then displays the next selection.
Exiting Pressing [x] at any time returns to the previous menu (and the Workstation
ignores any change on the current screen). To exit the configuration
program entirely, press [x].
5-2 Series 30/40 BASIC Guide
Clock
Date Format U.S. (MM/DD/YY), Int’l (DD.MM.YY)
Selects the format the Workstation uses to print the date. The U.S. format
is MM/DD/YY, where the month comes first; for example, June 24, 1994 is
06/24/94. The Int’l format is DD.MM.YY, where the day comes first; for
example, June 24, 1994 is 24.06.94
Date Selects the current date; note that the Workstation rejects months and days
that are invalid. Because the Workstation has no battery, it loses the date
every time you turn off power.
Time Selects the current time; note that the Workstation uses a 24-hour clock, so
in the afternoon, you must enter the current time plus twelve. Because the
Workstation has no battery, it loses the time every time you turn off power.
And while you have power applied, the Workstation’s clock is accurate
only to within a few minutes every day.
Keyboard/Display
Auto-Repeat Enabled, Disabled
This is the amount of time your operator must hold down a key before it
repeats. Note that the resolution of this parameter is 50 milliseconds, which
means that a value of 20 equals one second. If you must enable the auto-
repeat option, we recommend a repeat delay of 20.
This is the amount of time the unit waits between repeats while a key is held
down. The resolution of this parameter is 50 milliseconds, so a value of 2
means the unit repeats every 100 milliseconds, or 10 times each second. If you
must enable the auto-repeat option, we recommend a repeat rate of 1 or 2.
On-Line Configuration 5-3
This selection allows you to choose where the cursor moves after it prints to
the last column on a line. Following is how these selections control the
cursor’s movement:
Auto-CR The cursor moves to the first column of the current line.
Auto-CRLF If the cursor is not on the bottom line, it moves to the first column of the
bottom line; if the cursor is on the bottom line, the cursor movement
depends on your choice for the Screen End Action selection.
When the cursor is sent backwards, the same concepts apply. For example, when going
backwards from the first column, Auto-CR moves the cursor to the last column of the current
line, while Auto-CRLF moves the cursor to the last column of the previous line. Of course,
None leaves the cursor in the first column. We recommend that you set this parameter to
Auto-CRLF.
If you choose Auto-CRLF for the Line End Action selection described
previously, this selection allows you to choose where the cursor moves after
it prints to the last column on the bottom line. Listed below is how each
selection affects the cursor’s movement:
When the cursor is sent backwards, the same concepts apply. For example, when going
backwards from the first column of the top line, Wrap moves the cursor to the last column
of the bottom line, while Scroll moves the top line down and places the cursor at the last
column of the top line (which is now blank). Of course, None leaves the cursor in the first
column. We recommend that you set this parameter to Scroll.
Selects the cursor type. We recommend that you choose the Block cursor.
5-4 Series 30/40 BASIC Guide
Communications
Baud Rate 110, 30/400, 600, 1200, 2400, 4800, 9600, 19200
Selects the speed at which this port transmits and receives. We
recommend 9600, but in any event you must ensure that the device
connected to this port operates at the same speed.
Data Bits 7, 8
Selects the number of data bits in each byte transmitted. This must match
the setting of the device connected to this port. The combination of 7 data
bits, no parity, and 1 stop bits is invalid. In that instance, we recommend
you select 2 stop bits instead.
Stop Bits 1, 2
Selects the number of stop bits transmitted after each byte. This must
match or exceed the setting of the device connected to this port. In other
words, selecting 2 always works, but selecting 1 usually works. The
combination of 7 data bits, no parity, and 1 stop bits is invalid. In that
instance, we recommend you select 2 stop bits instead.
If the other device supports “software handshaking,” you can select XON/XOFF so that
the Workstation matches the other device.
Utility
Selecting the Utility function from the main configuration menu brings up the following menu:
Utility Menu
F1-Test F2-Upload
Test This section describes how to perform a “loopback” test on the Workstation’s
COM1 port so that you can check for a hardware failure. This test is useful
either to confirm or rule out that communication problems are related to
hardware problems.
Before you begin this test, you must plug a “loopback” connector into the COM1 port. This
connector is a female DB25 connector that you have modified according to one of the following
diagrams:
RS-232
Series 30/40 COM1
25-pin Female; RS-232 loopback
TXD 2
RXD 3
RTS 4
CTS 5
RS-422
Series 30/40 COM1
25-pin Female; RS-422 loopback
TXD + 14
RXD + 16
TXD – 15
RXD – 17
RTS 4
CTS 5
To perform this test, you must first gain access to the on-line configuration menu by cycling
power and pressing [F1] and [↵ ] simultaneously during the power-up self-test. To run the test,
you first press [F4] and then [F1].
After you start the test, the Workstation sends test data out through the transmitter and checks
for identical data coming back through its receiver. If everything works properly, the
Workstation displays the following screen:
Test Port:
COM1: Pass
On-Line Configuration 5-7
If the COM1 port does not work properly, the Workstation displays one of the following
messages:
Break Indicates that a “break” character was received; probably indicates a failed
transmitter.
Compare Indicates that the Workstation received different characters than expected; the
probable cause is a hardware failure.
Framing Indicates that the Workstation received a character with a framing error; the
probable cause is a hardware failure.
No CTS Indicates that the CTS input appears not to be asserted; this is caused either
because the jumper between RTS and CTS is missing from the loopback
connector or because the RTS output or CTS input has failed.
Overflow Indicates that the Workstation received too many characters; the probable
cause is a hardware failure.
Overrun Indicates that the Workstation was unable to process characters as fast as they
arrived; the probable cause is a hardware failure.
Parity Indicates that the Workstation received a character with a parity error; the
probable cause is a hardware failure.
Timeout Indicates that the Workstation received no characters at all; this is caused
either because the jumper between RXD and TXD is missing from the
loopback connector or because the transmitter or receiver has failed.
Upload This allows you to enable uploading of new firmware to the Workstation.
After selecting this option, you can follow the instructions on page 5-2 to
download firmware.
Ready to accept
firmware download.
Chapter 6
Service
This chapter describes service procedures and helps you troubleshoot some of the simple
hardware problems that can occur. The material in this chapter is also contained in DOC-
IWS-271, Series 30/40 Installation Guide.
The fuse holder is accessible only by removing the back cover and printed circuit board.
Follow these steps to replace the fuse:
1. Disconnect power to the unit. Disconnect any communications cable plugged into
COM1. Remove the unit from the panel.
2. Correct the condition (usually a power supply overload) that caused the fuse to blow.
3. Remove the four screws that hold on the back cover and slip off the back cover.
4. Locate the ribbon of plastic that connects the keyboard to the printed circuit board,
unlatch the black cap of the keyboard connector, and remove the keyboard tail.
The following two illustrations show the keyboard connector in the latched and
unlatched positions:
6-2 Series 30/40 BASIC Guide
5. Remove the four standoffs that hold on the printed circuit board and remove it as well.
6. Locate fuse F1 near the power supply terminal block. Using a continuity tester, check
the fuse to make sure it’s the problem.
7. Using needle-nose pliers, grab the center of the fuse and pull straight up. Install a
new fuse.
8. Install the printed circuit board back on the posts; be sure that the two spacers between
the display and the printed circuit board remain in place.
9. Insert the keyboard tail into the keyboard connector, and latch the connector.
10. Install the standoffs, replace the back cover, and replace the screws.
1. Disconnect power to the unit. Disconnect any communications cable plugged into
COM1. Remove the unit from the panel.
2. Remove the four screws that hold on the back cover and slip off the back cover.
3. The jumper is located on the component side of the printed circuit board near the LCD
display module. The jumper is labeled “E2” and has two positions: “RO” and “RW”.
The “RO” position is “Read-Only”; moving the jumper to that position protects the
memory from any intentional or accidental changes. The “RW” position is
“Read/Write”; moving the jumper to that position allows you to download new
firmware or a new application.
Troubleshooting
Virtually all apparent problems are caused by improper communications connections or
inadequate grounding.
No response to some keypresses Loose keyboard connector; faulty Unlatch keyboard connector, ensure keyboard
keyboard tail is fully seated, and re-latch connector;
return unit to factory for new keyboard.
Firmware download reports that Write-protection jumper is in “RO” Move write-protection jumper to “RW”
Flash is write-protected, empty position; using old version of position; use V1.6 or later of DOWNLOAD;
or invalid DOWNLOAD; faulty firmware or return unit to factory for new firmware.
Communications problems Bad cable; port failure Verify cable; use proper wire for RS-422;
check serial port with our loopback test as
described in Chapter 5.
Unit resets randomly or exhibits Loose or shorted power cable; short Check, repair and replace cable(s).
other intermittent problems in communications cable
Workstation not connected to earth Connect unit to earth ground.
Voltage potential between earth Connect all devices to the same earth ground.
grounds of Workstation and other
devices connected to its
communications ports
Loose integrated circuit inside Open unit, remove board and press chip into
socket.
Faulty Workstation power supply Return unit to factory.
Low line power voltage Raise voltage.
Faulty Workstation Return unit to factory.
Chapter 7
Concepts
Command/Run Modes
BASIC operates in two modes, the Command, or direct mode, and the Run, or deferred mode.
Some statements can only execute when BASIC is in the Command mode; others can execute
only in the Run mode, while the remainder can execute in both modes.
In Command mode, BASIC immediately executes one or more statements after you press [Enter].
Examples of statements that execute only in Command mode are NEW and DEL.
In Run mode, BASIC executes numbered program statements. Examples of statements that can
execute only in RUN mode are STOP and RESUME.
Console
Your IBM-compatible PC acts as a programming “console” when connected to the Workstation’s
serial port. Through the console, you can enter commands and edit your program.
The default Workstation serial port that connects to your console is COM1; you can assign a
different serial port as the console port with the REACT C command. For example, REACT C2
assigns port 2 as the console. See the description of the REACT command for more information.
Ports
You must connect your Workstation's COM1 port to your PC when you’re programming, and to
some other device when your program is running. This can be awkward, so we recommend that
you consider using an IWS-117 or IWS-127 for program development.
When communicating, the display and keyboard are also considered to be a port. The following
table summarizes the port names and numbers:
Statements
A BASIC program consists of numbered lines. Each line ends with a carriage return and
contains one or more statements. Each statement on the same line must be separated by a colon
(:).
The following rules apply to BASIC statements:
• Every line in a program must have a statement line number ranging between 0 and
65535. A good programming practice is to number line numbers by 10 (i.e. 10, 20, 30,
etc.), because BASIC doesn’t care if there are gaps between line numbers.
• A statement number can appear only once in a program.
• You do not have to enter statements in numerical order, because BASIC automatically
stores them in ascending order.
• A statement may contain no more than 250 characters.
• BASIC ignores blanks (spaces) except between quotation marks.
• A single line can contain more than one statement; a colon (:) separates each statement.
Remark (non-executable)
Statement separator (colon)
Operator
Command (as part of statement)
Statement line number
Floating point numbers contain eight significant digits; BASIC continually truncates results that
return more than eight significant digits. BASIC can accept and display numbers in three
formats:
Format Example
Decimal 34.98435
Hexadecimal 0A6EH
Scientific notation 1.2745 E+3
Hex numbers must begin with a digit between 0 and 9; to enter a hex number that starts with a
letter (A through F), you must precede the number with a 0. For example, you must enter the hex
number A00H as 0A00H. When a BASIC operation requires an integer, BASIC either rejects
any number that exceeds the range and returns an error or truncates any fractional portion so it
fits the integer format.
The word “constant” simply refers to a group of digits or a string of characters. For example,
123 is a constant, while A is a variable. Constants can range in value from ±1E -127 to
±.99999999 E + 127.
Concepts 7-3
Variables
Variables are named locations that hold changeable values. Different types of variables exist for
different types of values; for example, small integers, fractions or large numbers, and strings of
characters. Also, a variable can hold one value (“scalar variable”) or many values (“array
variables”).
Each type of value that a variable can hold is listed in the table below:
The first three variable formats identify different variables, even if the preceding letters are the
same. For example, the variable names A, A%, and A$ all refer to different variables.
Array variables are different from scalar variables of the same name; for example, A( ), A,
A%( ), A%, A$( ) and A$ all refer to different variables!
Scalar Variables Simple variables that represent a single value are called “scalar” variables. For
example, the variable “A” is a scalar variable that represents a single number.
Array Variables BASIC supports single-dimensioned variable “arrays,” where one variable
name refers to several separate variables, each identified by a number that
follows the name. The format of an array variable is “A(n)” where “n” is a
number that refers to a specific variable in the array. Chapter 11’s description
of the DIM statement contains additional information about array variables.
Memory BASIC allocates RAM memory space to variables in a “static” manner. This
Allocation means that each time the program refers to a new variable, BASIC allocates 8
bytes of memory to that variable (strings require more; see the description of
VARPTR in Chapter 11).
A BASIC program cannot de-allocate memory allocated to specific variables. For example, if
BASIC executes a statement like A = 4, you cannot tell BASIC later that the variable A no longer
exists. The only way to clear the memory allocated to variables is to execute a CLEAR
statement, which eliminates all variables.
Variable Names A variable is a named data location that a BASIC program can examine and
change. A variable name must start with a letter, but it may include both
numbers and letters. Only the first two characters of the variable name are
significant. For example, “A” is a valid variable name, as is “A1234;”
however, BASIC considers “A1234” to be the same as “A1.”
Variable names cannot include any words that BASIC reserves for its own use.
Among the reserved words are all of the statements listed in Chapter 11. For
example, TOP is not a valid variable name because it contains the word TO,
which BASIC uses in a FOR statement. As another example, STOP is not a
valid variable name because it is a BASIC statement.
Floating point Unless otherwise indicated, variables refer to floating point numbers. For
Variables example, A, A1, BAD, and STARTING are all valid floating point variable
names. Floating point numbers range in value from ±1E -127 to ±.99999999 E
+ 127, but with a resolution of only 8 digits. For example, when BASIC
multiplies 1.2345678 by 11, it truncates the result of 13.5802458 to 13.580245.
Integer Variables Integer variable names end with a % character; for example, A% is an integer
variable, not a floating point variable. Integer numbers range in value from -
65,535 to 65,535. (Integers in most BASICs have a range of only -32,768 to
32,767.)
String Variables String variable names end with a $ character; for example, A$ is a string
variable. String variables have a default length of 10 characters; your program
can set up a different default string length for all strings as well as specify a
length of up to 254 characters for any specific string. Consult the description
of SDIM in Chapter 11 for more information.
Built-in Variables Built-in variables contain values that BASIC assigns itself, depending on the
circumstances. For example, ERR contains the number of the last error that
occurred. Note that all characters in the variable name are significant for built-
in variables. In other words, ER is not the same variable as ERR.
Operators Operators manipulate one or two operands and return a result. Typical dyadic
(two-operand) operators include add (+), subtract (-), multiply (*), and divide
(/). Typical unary (one-operand) operators are exponentiation (^), SIN (sine),
COS (cosine), and ABS (absolute).
Concepts 7-5
Relational Relational expressions compare two expressions and return a true/false result.
Expressions The numeric value of true is 65,535; the numeric value of false is 0. A
relational expression can be any arithmetic expression, although typical
relational expressions use the relational operators shown below:
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
The relational operators also work with strings; string1 is considered “less than” string2 if it is
either shorter than string1 or if the first character that doesn’t match has a lower ASCII value.
For example, “TO” is less than “TAP” and less than “TS.”
Memory Usage
Page C-13 of the Appendix contains a drawing that shows how BASIC uses the Workstation’s
memory. You may want to refer to this drawing as you read the following text.
While you're creating a new program, BASIC stores your program at the bottom of available
RAM; as your program increases in size, BASIC uses RAM memory at increasing addresses.
While you’re editing your program, the entire RAM is available.
During program execution, BASIC stores normal variables starting at the top of available RAM
(as specified by MTOP, whose default value is the highest RAM address available); as you add
variables, BASIC stores those variables at decreasing addresses in memory. BASIC stores array
variables starting at the end of your program and works up.
BASIC can run out of memory during editing if your program expands beyond the available
RAM. If this happens, then your program is certainly too big, because BASIC allocates memory
for variables only while your program is executing. BASIC can also run out of memory while
your program is running, if it detects that normal variable memory has overlapped your program
or array variable memory.
In either case, BASIC issues a MEMORY FULL error and you must slim down your application.
After you have completed your application, you must save it in the Workstation's permanent
memory by copying it to ROM. When the Workstation powers up, it copies the program to RAM
and runs out of RAM. Please see the description of the ROM command in Chapter 11 for
complete information.
Chapter 8
IWS-SETUP-BP-30, the setup package for the Series 30/40 Workstation, includes a terminal
emulation program called BP, along with several BASIC programs that contain interesting
examples and useful utilities (described below). This chapter shows how to use BP to create,
upload, modify, and download BASIC programs.
Starting Up BP
You should make a copy of your BP diskette and save the original as a backup.
Disk Files In addition to the BP software itself, BP.EXE, the BP diskette contains the
following files:
BP.CFG Contains information about your configuration,
including window colors, baud rate, and so on.
You can change the configuration information by
following the instructions on page 9-6.
IHEX30/40.LST Allows you to dump the contents of memory to a
disk file using the Intel hex format. This is
especially useful for OEMs who use EPROM
program memory.
To run BP, you must first install the software as described in Chapter 4.
After you install the software, type BP and press [Enter]; your PC displays
the following:
WELCOME TO BP
1 Help 2 Edit 3 Cmd 4 DOS 5 Recv 6 Send 7 DCap 8 Dual 9 Setup 10 Exit
BP also has additional functions that allow you to send disk files to the Workstation, receive
program listings from the Workstation and store them on disk, and edit a line in the BASIC
program stored in the Workstation.
The display above is the standard terminal emulation screen; pressing one of the function keys
[F1] through [F10] causes BP to perform one of its additional functions.
If your PC has a 25-pin serial port, you will need to purchase a standard 9-to-25 pin adapter to
use with the cable that comes with IWS-SETUP-BP-30.
Turn on the Workstation and wait for it to complete its self-test. At the end of the test, it
displays the following message:
Welcome to V5.50
Series 30/40 BASIC
When the Workstation completes its self-test, it checks to see if it has an “auto-start” program
in memory. If it does, it runs the program. If not, then it sends the following message to your
computer:
NEMATRON CORPORATION
Series 30/40 BASIC
Version 5.50
READY – RAM 1
>
The “>” symbol indicates that the BASIC interpreter is waiting for you to enter a command. If
you don’t see that symbol, the Workstation is probably executing a program; try holding down
How to Use BP Software 8-3
[F1] and [↵ ] simultaneously to halt the program (see Chapter 9 about Halting a Program for
more information).
Summary of BP Functions
Line Editing BP has a convenient single-line editor that allows you to change a line in
your program without retyping the entire line. To use the editor, press [F2]
to call up the following:
You can select a line to edit by typing in its line number and pressing [Enter]. BP then
retrieves the line from the Workstation and displays it on the PC’s display. At that point, you
can change the line and then press [Enter] to send the line back to the Workstation. Listed
below are some special editing keys and their corresponding functions:
Command Editing BP allows you to edit any line you recently typed, including both direct
commands and program lines. To use the command editor, press [F3] to
call up the following display
:
========================= Edit ====================== ins =
When you enter the command editor, BP displays the last line you typed. You can select a
previous line by pressing [F3] or you can create a new line by pressing [F5].
How to Use BP Software 8-5
Enter the filename of your BASIC program, including the drive location and/pathname. For
example, if you are uploading MYPROG.TXT which is located on a disk in drive A, enter the
name of the file as A:MYPROG.TXT.
BP displays a running count of the number of lines transmitted. If this number does not
continually increase, there is a problem with your software configuration or hardware setup.
We recommend you use the statement OPEN "COM1:IB,CE,LF,TX0" to set the
communications parameters of your console port. You can abort the transmission by pressing
[Esc].
Enter the filename of your BASIC program, including the drive location and/or pathname. For
example, if you are uploading MYPROG.TXT and you want to place the file on a disk in drive
A, enter the name of the file as A:MYPROG.TXT.
BP displays a running count of the number of lines received. If this number does not
continually increase, there is a problem with your software configuration or hardware setup.
We recommend you use the statement OPEN "COM1:IB,CE,LF,TX0" to set the
communications parameters of your console port. You can abort receiving by pressing [Esc].
8-6 Series 30/40 BASIC Guide
Configuring BP [F9]
Pressing [F9] allows you to view and change the current settings for BP. When you enter the
Setup function, you see the following screen. The function key legend at the bottom of the
screen indicates the configuration choices available to you; to exit any of the configuration
choices, press [Esc].
Color If your PC has a color monitor, you can configure the colors of both the text
Configuration and background for all of the windows that BP displays.
To configure window colors, press [F9] until that section of the screen is highlighted. Then
press [↑] or [↓] to highlight the current window selection. The bottom left corner of the screen
shows a sample of the current text and background colors for the selected window. You can
change the text colors by pressing [F2] and [F3], and you can change the background colors by
pressing [F5] and [F6].
How to Use BP Software 8-7
Serial Port You can set up the PC’s serial port that BP uses to talk to the Workstation by
Configuration pressing [F9] until that section of the screen is highlighted. Press [↑] or [↓] to
select a communications parameter, and press [← ] or [→ ] to choose among the
various selections for each parameter. We recommend that you avoid using
19,200 baud for downloading, because it is not reliable.
Display You can set up parameters for the History window by pressing [F9] until that
Configuration section of the screen is highlighted. The Split Row parameter selects the size
of the History window, and the Split Window parameter selects whether the
History window is on or off when BP first begins. To choose between the
parameters, press [↑] or [↓]. To choose among the various selections for each
of these parameters, press [← ] or [→ ].
Save and After you change your configuration settings, you can press [F7] to save them
Restore Defaults on disk so that BP remembers your settings the next time you use BP. (BP
stores your configuration settings in the file titled BP.CFG.) If you want to
restore your configuration settings to the factory selection, press [F8].
Additional BP Functions
DOS Gateway You can exit BP temporarily to perform DOS functions or run another
program and then return to BP where you left off. To exit BP, press [F4]; to
re-enter BP, type EXIT and press [Enter] after the DOS prompt. If the file
COMMAND.COM is not in the current directory or path, then BP displays
the error message CAN’T SPAWN.
Data Capture There may be occasions when you want to capture data on disk that the
Workstation generates. To initiate data capture, press [F7] to display the
following screen:
After you enter the filename, the display changes to show the number of bytes (characters) that
BP has received so far.
In order to conclude the data capture function, you can either press [Esc] or the Workstation
can send ASCII code 1Ah, which is equivalent to a [Ctrl]-Z. You can do this with the
statement PRINT CHR$(1Ah).
History Window In the terminal window, BP displays the last 23 lines that it received from the
Workstation. BP saves the last several hundred lines, however, and you can
review these by displaying and scrolling through the history window. To
display the history window, press [F8]; to cancel the history window, press [F8]
again.
To move around in the history window, press [Page Up], [Page Down], [↑], [↓], [Home], and
[End].
8-8 Series 30/40 BASIC Guide
Hex Display BP can display every character it receives in “hex” format instead of the
normal ASCII format. To select the hex mode, press [Alt]-H; when BP is in
the hex mode, it displays the word “HEX” in the upper left corner of the
screen. To cancel the hex mode, press [Alt]-H again
Keyboard BP has a “keyboard macro” capability that allows you to type a string of
Macros characters by pressing [Alt] and a single digit simultaneously. To set up a
keyboard macro, you must press [Alt]-M to enter the macro editor.
To change a macro or enter a new macro, press [↑] or [↓] to select the macro you want to edit.
Then press [← ] or [→ ] to position the cursor, after which you simply type the keystrokes you
want in that macro. Keys such as [Enter] are displayed as odd symbols such as a musical note.
To save your changes, press [F8]. To cancel any changes to your current macro, press [F5]; to
cancel all changes, press [F9]. To erase the current macro, press [F3].
To use a macro, hold down [Alt] while pressing a digit. For example, [Alt]-0 invokes the first
macro.
As delivered, several of the macros are already set up to perform useful functions. For
example, [Alt]-0 opens COM0 according to our recommended settings. Of course, you can
change these macros too.
How to Use BP Software 8-9
Troubleshooting
If BP is unable to complete a function that you request, it displays an error message which
usually appears in the middle of your screen. This section describes those error messages and
offers possible solutions:
Can’t open serial port When you start running BP, it checks for availability of the serial port (COM1 or
COM2) assigned for its use. The factory setting is COM1, but you can access the setup
screen to change the serial port to COM2 by pressing [F9] while BP is running.
If BP’s serial port appears unavailable, it displays the message “Can’t open serial port”
on the bottom of your screen and terminates execution.
There are three possible causes for this message:
1.BP may be set up to use COM2 when the PC has no COM2 port. This usually occurs
when you set up BP to use COM2 on a PC with two serial ports, and then copy both
BP.EXE and BP.CFG to another PC.
2.You computer may already utilize the selected serial port for some other function,
such as a remote file server. In that case, you must prevent your PC from logging on
to the file server when it boots; this typcially requires you to chagne your
AUTOEXEC.BAT file and re-boot.
Can’t spawn When you press [F4] to exit BP temporarily in order to perform a DOS function, BP tries
to run the COMMAND.COM file. If BP is unable to find COMMAND.COM, then it
displays the message “Can’t spawn.”
This problem usually occurs because your path does not include the directory that contains
COMMAND.COM. The usual solution is to change your path specification in your
AUTOEXEC.BAT file to include the COMMAND.COM directory. An alternative is
simply to copy COMMAND.COM to the same directory that contains BP.EXE.
Time-out There are a few instances where BP waits for a response from your Workstation; if the
Workstation does not respond within a reasonable period of time, BP displays the message
“Time-out.”
This usually occurs if you press [F2] or [F5] while you’re in the middle of typing a line,
instead of pressing the key at the “>“ prompt.
The time-out error can also occur if you are downloading and the Workstation’s console
port (usually COM1) is not opened with the IB parameter. We recommend you use the
statement OPEN "COM1:IB,CE,LF,TX0" to open your console port.
Garbled Programs or Make sure COM1 is opened properly: OPEN “COM1:IB,CE,LF,TX0”. You can press the
Downloading [F4] key on the Workstation to force COM1 to the proper default settings.
Problems
Chapter 9
Application Suggestions
This chapter describes some of the Workstation’s special capabilities, including keyboard
functions, auto-starting and terminating programs, protecting programs and data, controlling
the display and LEDs, performing functions at regular time intervals, and communicating with
intelligent devices.
Halting a Unless you provide otherwise, pressing [Ctrl]-C terminates execution of a running program.
Program; You can disable [Ctrl]-C entirely by opening each port without the CE parameter, or you
can set up your program to handle [Ctrl]-C as an error via your own error-handling routine
[Ctrl]-C (enabled with the ON ERROR GOTO command).
The Workstation senses [Ctrl]-C from either the current input port or the Workstation’s
keyboard, provided both are configured with the “CE” parameter. The Workstation ignores a
[Ctrl]-C received on a serial port that is not the current input port, regardless of that port’s CE
parameter.
If [Ctrl]-C is not enabled, then the only way to stop execution of your program is to cycle
power. If your program is in RAM memory, however, any changes since you last copied the
program to ROM will be lost. Moreover, if you have set up your program to run automatically
with the REACT command, then you're absolutely stuck. You must download new firmware in
order to erase your program.
On-Line You can select almost all of the Workstation’s operating parameters either through the on-
Configuration; line configuration menus or through the OPEN statement. Typically, you should use the
OPEN command to change parameters.
[F3]
You can enter the Workstation’s on-line configuration menus by pressing the [F3] key when
the unit is not running a program. (Pressing [F3] won’t work if another keypress remains in
the buffer; you may have to press [F1]-[↵ ] or cycle power to empty the buffer, and then press
[F3] again.) You should consult Chapter 6 for details.
9-2 Series 30/40 BASIC Guide
Restore COM1 When BASIC is in the command mode (no program is running), you can press [F4] to reset
Defaults; [F4] the COM1 communication parameters to their default values of 9600,8,N,1. This simplifies
program development because you can easily set COM1 to known parameters after your
program stops running.
If you use the Series 30/40 Workstation, you must continually switch COM1 between your PC
and another device. This can be inconvenient, not only because of the continual need to switch
cables, but also because your PC and your other device may require different communications
parameters. In that case, you need some way to switch your program back and forth between
two sets of communications parameters.
In any event, you still face a debugging problem: if your program terminates with an error
message, BASIC sends that error message to COM1, which will probably be connected to
another device, so you won’t see the message. You can force the Workstation to display the
error message on its display instead of sending the message to COM1, but to do that you must
set up your program to run automatically with the REACT R command, copy your program to
ROM, and then cycle power to the Workstation. Once your program is in ROM, the only way
to change it is to download firmware again.
At any time that your program isn’t running, you can press [F4] on the Workstation’s keypad
to restore the COM1 communications parameters to their default values.
We suggest you implement an ON ERROR handler so that any error causes the program first to
change the COM1 communications parameters to the default values needed for your PC, and
then to terminate execution. Your program should also open COM0 with the CE parameter so
you can press [F1]-[↵ ] at any time to halt program execution.
Unfortunately, your error-handler only sees errors that are “recoverable”; there are several non-
recoverable errors that cause program execution to terminate immediately, without regard to
the ON ERROR command. As a result, we suggest you postpone communications testing until
late in your project and wait until then to implement an error handler.
Following are sections of a model program that switches COM1 between two sets of
communications parameters:
The Workstation stores your program in the same Flash memory where it stores the BASIC
firmware itself. When the Workstation powers up, it copies the program from Flash to RAM.
Because Flash cannot be changed without completely erasing every location, you must
download new firmware if you want to make any changes to a program that you have already
copied to Flash.
To copy a program to Flash, you would set up your REACT command and then use a command
in the form “ROM = RAM 1”, which copies the first program in RAM to Flash and makes the
current REACT setting permanent. See the description of the ROM command in Chapter 10
for more information.
Auto-Starting Programs
You can set up the Workstation so that after the power-up self-test, it automatically executes
the program stored in its memory. To do this, you must use the “REACT R” command before
you copy your program to the Workstation's permanent Flash memory. This command tells the
Workstation to run your program automatically. See the description of the REACT command
in Chapter 10 for a complete description of the functions the Workstation can perform after
power-up.
Program Protection
Many OEMs and systems houses hope to prevent their customers from modifying their
programs, plus prevent their competitors from copying their programs. To do this, you must
both prevent your program from halting plus lock it in the run mode if it does halt.
Most programmers set up an error-handling routine using the ON ERROR GOTO capability in
order to “trap” errors. When any non-fatal error occurs, including [Ctrl]-C, the Workstation
transfers program execution to the error routine. At that point, the error routine should provide
a way to recover gracefully from any error condition.
However, if a fatal error such as SYNTAX ERROR or OUT OF MEMORY occurs, program
execution terminates. (Fatal errors usually indicate serious programming errors, so they
usually occur during the debugging process instead of after final installation.) In case of a fatal
error, you can set up your program to re-run automatically by using the “P” parameter in your
REACT command. For example, REACT R,P sets up your program to auto-start and protects it
by locking it in the Run mode.
Note If you lock your program in the run mode, you should provide
a secret way to terminate program execution so that you can
provide field service. If your program is locked in the run
mode, you can terminate execution only by erasing the
program.
If the data never changes, then one simple way to store it permanently is by embedding data in
your program with DATA statements and copying that data to variables by using READ
statements. See Chapter 10 for details.
If you want to store data permanently but need the capability to change it while your program
is running, you can use the ST@ command to write variables to memory and LD@ to retrieve
them later. This technique has a significant limitation: although your program can write data
to a permanent memory location, your program cannot change this data later. You can
implement a technique to save changed data in unused locations that are at progressively
higher addresses in memory, but eventually you could run out.
The reason for this limitation is that the only permanent memory that the Workstation provides
is Flash, which is the same place that the Workstation stores its firmware and your program.
Individual locations in Flash cannot be altered without erasing the entire Flash first, so every
time your program stores data, it must use memory that was previously empty. For complete
instructions and a sample application, please see the description of the LD@ command in
Chapter 10.
If your application requires the capability to change memory without limitation, then you
should use a Nematron Series 110 or Series 120 Workstation instead.
You can configure the system’s actions at the end of a line and at the end of a screen with the
OPEN command. See the discussion of OPEN in Chapter 10 for more information.
Time-Driven Functions
The ON TIME control structure provides a way to interrupt normal program execution in order
to perform a subroutine at a scheduled time.
You should see the discussion of ON TIME in Chapter 10 for detailed information.
Chapter 10
Commands
This chapter describes all of the commands and statements in the Series 30/40 BASIC
language.
ABS
Returns the absolute value.
ABS(expr)
Discussion The absolute value of a number is always positive or zero. Like all numeric
functions, ABS may appear on the right of an assignment statement, within a
PRINT statement, and as part of an arithmetical expression.
ASC
Returns the ASCII value of the first (or specified) character of a
string.
ASC(sexpr{,iexpr})
Where sexpr is any string expression and iexpr is an optional offset (between 1 and 254) into the
string.
Discussion Like all numeric functions, ASC may appear on the right of an assignment
statement, within a PRINT statement, and as part of an arithmetical
expression. The ASC operator returns the ASCII value of the first character of
the string expression. ASCII values range between 0 and 255.
If the optional offset is included, then ASC returns the ASCII value of the
selected character, where an offset of 1 selects the leftmost character of the
string. This syntax is equivalent to ASC(MID$(sexpr, iexpr,1)).
Examples 10 A$ = "DUCKS"
20 PRINT ASC(A$)
>RUN
68
READY – RAM 1
>
>PRINT ASC("DUCKS")
68
>
10 A$ = "DUCKLINGS"
20 PRINT ASC(A$,4)
30 REM In string A$, print ASCII of 4th letter
>RUN
75
READY – RAM 1
>
Commands and Statements 10-3
ATN
Returns the arctangent.
ATN(expr)
Discussion Like all numeric functions, ATN may appear on the right of an assignment
statement, within a PRINT statement, and as part of an arithmetical
expression. The result of the ATN function is a value expressed in radians in
the range of -PI/2 to PI/2 (-1.570796327 to +1.570796327).
ATN Ø = a/b
Ø
b
>RUN
?24
?24
1 .78539804 44.999985
READY – RAM 1
>
10-4 Series 30/40 BASIC Guide
BIT
Reads from or writes to a bit within an integer.
BIT(iexpr1, iexpr2)
When used in an expression, BIT returns the status of bit number iexpr2 (1–16) within iexpr1
(0–65,535). Bit 1 is the least significant bit.
When used on the left side of an equal sign, iexpr1 must be either a numeric variable whose
value varies between 0 and 65,535 or a DBY or XBY location.
Discussion The BIT statement reads from or writes to a specific bit within the 16 bit
integer (an integer varies between 0 and 65535) or certain special integer
variables, such as DBY() and XBY().
Examples The following program defines variable A to be equal to 9, then prints out each
of the variable’s lowest 16 bits.
10 A = 9
20 FOR I = 16 TO 1 STEP -1
30 PRINT BIT(A,I);
40 NEXT
>RUN
0000000000001001
READY – RAM 1
>
In the above example, we know that if we force bit number 8 to a 1, the integer will have the
value 137. The following program forces bit 8 to a 1 and prints out the resulting value.
10 A = 9
20 PRINT "The original integer is " ;A
30 BIT(A,8) = 1
40 PRINT "The new integer is ";A
50 PRINT "The new bit pattern is ";
60 FOR I = 16 TO 1 STEP -1
70 PRINT BIT(A,I);
80 NEXT
>RUN
The original integer is 9
The new integer is 137
The new bit pattern is 0000000010001001
Commands and Statements 10-5
CALL
Goes to a built-in routine or machine language subroutine.
CALL iexpr
Where iexpr is either the address of a machine language subroutine or, if less than 128, the
number of a “built-in” CALL.
Discussion The CALL statement calls a machine language subroutine. Integers between 1
and 127 refer to built-in subroutines (described in Chapter 14); otherwise, the
integer is the memory address of a machine language subroutine.
CALLs are described in detail elsewhere in this manual; however, a summary is listed below:
CBY
Retrieves a byte from program memory.
CBY(iexpr)
Discussion The CBY operator returns the data from the code address specified by the
integer. Because the only code space is a Flash EPROM, you cannot use CBY
to write data to code space.
>RUN
171
READY – RAM 1
>
Commands and Statements 10-7
CHR$(iexpr)
Discussion CHR$ is the converse of the ASC( ) operator. It converts a numeric expression
into an ASCII character. CHR$ is a convenient way to print characters not
found on the Workstation’s keyboard or to print double quotes. This is the only
way to print double quotes since they are the delimiter for text strings.
READY – RAM 1
>
10 FOR I = 48 TO 57
20 PRINT CHR$(I);
30 NEXT
>RUN
0123456789
READY – RAM 1
>
>RUN
"Nematron"
READY – RAM 1
>
10-8 Series 30/40 BASIC Guide
CHR$(iexpr) = iexpr1,iexpr2,iexpr3,iexpr4,iexpr5,iexpr6,iexpr7,iexpr8
Where iexpr is a number in the range of 16 to 23 and iexpr1 through iexpr8 are numbers
between 0 and 31 that represent a bit pattern for each row.
Discussion When used on the left side of the equals sign, CHR$ provides a way to define a
programmable character. The argument iexpr is the character’s ASCII code; its
valid values are 16 through 23.
The eight values listed to the right of the equals sign each contains the bit
pattern for a row, where the first value is the top row and its low bit is the
rightmost bit.
The example program below defines the following character under ASCII code
16:
Data Row D5 D4 D3 D2 D1
0Fh 1 . l l l l
11h 2 l . . . l
11h 3 l . . . l
0Fh 4 . l l l l
05h 5 . . l . l
09h 6 . l . . l
11h 7 l . . . l
CLEAR
Clears all variables.
CLEAR
Discussion CLEAR initializes variable memory to zero; it erases all variables entirely, so
any strings or arrays your program previously declared with the SDIM or DIM
statements are also erased.
Examples 10 A = 23 : B = 45 : C = 12
20 A$ = "Message"
30 PRINT A$
40 PRINT A,B,C
50 CLEAR
60 PRINT A$
70 PRINT A,B,C
>RUN
Message
23 45 12
0 0 0
READY – RAM 1
>
>A = 23
>PRINT A
23
>CLEAR
>PRINT A
0
10-10 Series 30/40 BASIC Guide
CLOCK
CLOCK 1 resets the special TIME variable to 0; CLOCK 0
disables ON TIME interrupt service.
CLOCK 0
or
CLOCK 1
Discussion The CLOCK commands operate with the ON TIME statement to enable
BASIC to call a subroutine at time-based intervals. CLOCK 1 resets the
TIME variable to 0, which is typically needed immediately after the ON
TIME statement as well as at the end of the subroutine. CLOCK 0 turns off
the ON TIME function.
>RUN
Main Program
Interrupt routine entered here
Interrupt routine
Interrupt routine
.
.
Main Program
Commands and Statements 10-11
CLS
Clears the Workstation’s display.
CLS
Discussion The CLS statement clears the Workstation’s display and moves the cursor to
the upper left corner of the screen.
Examples 10 CLS
>RUN
READY – RAM 1
>
>CLS
10-12 Series 30/40 BASIC Guide
CONT
Resumes execution after the program has aborted.
CONT
Discussion The CONT command causes the unit to resume execution of a BASIC •
program where it left off. A program that ends normally or with an error
cannot CONTinue. A program can CONTinue if it stopped for one of the
following reasons:
Typing CONT resumes execution of your program. Between the stopping and the re-starting
of the program, you may display or change the value of variables; however, you may not
CONTinue if you modify the program or if the program stopped because of an error.
>RUN
1
2
3
4 - (press [Ctrl]-C on the keyboard here)
STOP - IN LINE 20
READY – RAM 1
>I=10
>CONT
10
11
Commands and Statements 10-13
COPY
Copies a range of memory from one area to another.
COPY iexpr1,iexpr2,iexpr3
Where iexpr1 is the starting address of the data to be copied, iexpr2 is the beginning of the area
to copy to, and iexpr3 is the number of bytes to copy.
Discussion The COPY command allows your program to copy data from one area of
memory to another. The COPY command performs correctly whether the data
to be copied are above or below the destination address.
>RUN
READY – RAM 1
>
10-14 Series 30/40 BASIC Guide
COS
Returns the cosine.
COS(expr)
Discussion Like all numeric functions, COS may appear on the right of an assignment
statement, within a PRINT statement, and as part of an arithmetical
expression. The argument for the COS function is a value expressed in
radians; divide degrees by 57.29577 to convert degrees to radians.
Trigonometric The cosine of a triangle is the length of the adjacent side divided by the length
Relationship of the hypotenuse side (b/c). See the figure below for the relationships between
COS Ø, side b, and side c.
+1
c
SINE 0
COS Ø = b/c
b =COS Ø c
Ø c =b/COS Ø
-1
b 0 90 180 270 360
ANGLE (degrees)
>RUN
Enter angle in degrees 45
The cosine of the angle is .7071067
READY – RAM 1
>
Commands and Statements 10-15
CR
Generates carriage return but suppresses line feed in PRINT
statement.
CR
Discussion The CR statement in a PRINT statement prints a carriage return only. This is
useful when your program must “overprint” data that is continuously updated.
Note Typically, CR is the last item in a PRINT statement and is
followed by a semicolon (;). If there is no final comma or
semicolon, then the PRINT statement defeats the CR function
because a PRINT statement normally concludes by printing a
carriage return/line feed.
>RUN
65 A (Display "overwrites" on this line)
READY – RAM 1
>
10-16 Series 30/40 BASIC Guide
CSRLIN
Identifies the line number of the display’s cursor.
CSRLIN
Discussion The CSRLIN statement returns the current line number of the cursor on the
Workstation’s display. The value returned is between 1 and 2.
Examples 10 CLS
20 PR#0
30 PRINT"Hello"
40 PRINT"There"; POS, CSRLIN
50 PR#1
>RUN
READY – RAM 1
>
After execution of this example, the Workstation’s screen shows the following:
Hello
There 6 2
Commands and Statements 10-17
DATA
Stores numeric or string data in a program.
Discussion The READ statement gets its data from the constants following DATA
statements.
Because BASIC does not execute DATA statements themselves, you typically
include them at the end of your program. Each time BASIC executes a READ
statement, it points to the next DATA item. If your program tries to READ
when there is no data, the Workstation displays the message “ERROR: NO
DATA.” The RESTORE command points back to the first DATA item in the
program.
Examples 40 READ A, B, C, D, E
50 PRINT A, B, C, D, E
60 READ A$, B$, C$
70 PRINT A$, B$, C$
80 DATA 12,24,54,67,78
90 DATA "abc","def","ghi"
>RUN
12 24 54 67 78
abc def ghi
READY – RAM 1
>
10-18 Series 30/40 BASIC Guide
DATE$
Returns or sets the month, day and year.
DATE$ = “mm/dd/yy”
or
DATE$ = “dd.mm.yy”
Where DATE$ either sets the date (as shown above), or returns the date.
Discussion DATE$ can be set as shown in the box above. If parameters are omitted, the
unit doesn’t change them. For example, if the current date is 12/30/95 and the
unit executes “DATE$ = 11”, then the unit sets the date to 11/30/95
.
The Workstation can set and return the date in the international format (“dd.mm.yy”) if you
have previously used the on-line configuration menu to select the international format. See
Chapter 5 for instructions.
The Workstation updates DATE$ strictly through software time keeping, which is accurate
only to within a few minutes a day.
>RUN
Enter today's date: 12/24/94
12/24/94
READY - RAM 1
>
Commands and Statements 10-19
DBY
Reads from or writes to internal RAM or special function
registers.
DBY(expr)
Where expr is a number between 0 and 255; DBY returns a number between 0 and 255.
Discussion The DBY operator retrieves or assigns a value to the microprocessor’s internal RAM memory or special
function registers at address expr. Both the value and the address must be between 0 and 255 inclusive.
Addresses from 0 to 7Fh refer to the microprocessor’s internal RAM memory; BASIC uses all of this
memory and leaves nothing available for user data storage.
Addresses from 80h to 0FFh refer to special function registers that control the operation of the
microprocessor itself; some of those registers are shown below:
>RUN
13
READY – RAM 1
>
10-20 Series 30/40 BASIC Guide
DEL
Deletes all or part of a program or all programs.
Where line#1 and line#2 are any valid line numbers in the program or prog# is any valid
program number.
Discussion You can use the DEL command to remove one or more lines from your
program.
Before the system actually deletes all programs from memory, it displays the following prompt:
“Delete all programs (press backspace to delete)?” To follow through with deleting, you must
press the [Backspace] key on your console.
Examples >LIST
10 SDIM A$(20) : REM Set string length to 20
20 A$ = "Eldridge, Iowa"
30 L = LEN(A$)
40 PRINT "Length of string is",L,"characters"
50 PRINT A$
READY – RAM 1
>
READY – RAM 1
>DEL 20,30
>LIST
10 SDIM A$(20) : REM Set string length to 20
40 PRINT "Length of string is",L,"characters"
50 PRINT A$
READY – RAM 1
>
Commands and Statements 10-21
>DEL RAM 1
READY – RAM 1
>LIST
READY – RAM 1
>DEL RAM
Delete all programs (press backspace to delete)?
READY - RAM 1
>
10-22 Series 30/40 BASIC Guide
DIM
Declares the size of an array variable.
DIM nvar(iexpr1)
or
DIM svar(iexpr1,iexpr2)
Discussion The DIM statement creates a numeric array named nvar with a size (i.e.,
number of elements) of iexpr1 or a string array named svar with a size of
iexpr1 and a string length of iexpr2. The maximum number of elements in
an array is 254, and the maximum length of each string is 254. The value of
each element in an array is initially zero.
You can change the default string length of 10 characters with the statement
SDIM = x, where x is the desired default length. For example, if you want a
default string length of 20, your program would include the statement SDIM =
20 before any statements that declare a new string.
You cannot change the size of an array after you have dimensioned it; any
attempt to do so results in a “REDIMENSION ERROR.”
The amount of memory used (in bytes) for a numeric array is 14 plus 6 times
the array size; for example, DIM A(100) allocates 14 + 6 * 100, or 614 bytes
of memory. The amount of memory used for a string array is (string length +
1) times (array size plus 1) plus 8; for example, DIM A$(15,20) allocates (15
+ 1) * (20 + 1) + 8, or 344 bytes of memory.
A DIM statement can handle more than one variable, as shown in the first
example.
This line should be early in the program and assigns an array size of 20 to variable A, an array
size of 35 to variable B, and an array size of 30/40 to variable C$ (where each string is 22
characters long).
Commands and Statements 10-23
The program below produces a redimension error at line 120 because line 20 creates the array
simply by referring to an array variable:
10 X = 0
20 PRINT A(X)
30 DIM A(5)
>RUN
ERROR: REDIMENSION - IN LINE 30/40
30 DIM A(5)
------- X
10-24 Series 30/40 BASIC Guide
DIR
Prints a directory of all programs in memory.
DIR
Discussion The DIR command prints a list of all programs in memory, with each
program’s starting address and length (in hex) and any REM statement that
appears on the first line.
In order to use the DIR command to its best advantage, the first line of each program should be
a REM statement that lists the program’s title and purpose.
Examples In the following example, the first line of the first program contains a REM
followed by “TEST Program 1”; the first line of the second program contains
no REM statement:
>DIR
RAM 1 (1000H,1982H) - TEST Program 1
RAM 2 (2982H,0254H) -
ROM (A000H,0125H) - TEST Program in ROM
READY - RAM 1
>
Commands and Statements 10-25
DO . . . UNTIL
Loops until a condition is true.
DO
--
UNTIL rexpr
Where rexpr is a condition that must be true in order to terminate the loop.
Discussion
The DO and UNTIL statements provide a means of “loop control” within a
BASIC program. BASIC executes all statements between the DO and the
UNTIL until the relational expression following the UNTIL statement is true.
You can “nest” additional control loops in a DO - UNTIL loop, such as DO - WHILE and FOR
- NEXT. The program example on the right below shows a DO - UNTIL loop nested in
another DO - UNTIL loop.
Nesting Limits The DO, FOR and GOSUB statements all allow BASIC to repeatedly execute a
series of statements. Every time BASIC executes one of these statements, it
saves information that it eventually needs to execute the WHILE, UNTIL,
NEXT or RETURN that marks the end of the series of statements.
BASIC reserves an area that we call the “control stack” to save the information it needs for any
active DO, FOR and GOSUB statements. This control stack can hold 178 bytes; DO and
GOSUB statements each require three bytes, while the FOR statement requires 18 bytes. Your
program can nest these statements in any combination, up to the limit of the control stack.
For example, your program could contains GOSUBs that in turn call GOSUBs, until your
program has reached 59 levels (178/3) of nesting. However, your program can contain only 9
levels of FOR loops. Your program can combine these so that FOR loops contain GOSUBs,
which themselves contain DO loops and FOR loops, and so on, up to the limit of 178 bytes.
If your program exceeds the capacity of the control stack, then BASIC issues “C-STACK”
errors.
10-26 Series 30/40 BASIC Guide
READY – RAM 1
Commands and Statements 10-27
DO . . . WHILE
Loops while a condition is true.
DO
--
WHILE rexpr
Where rexpr is a condition that keeps the loop going. When the expression is no longer true,
the loop terminates.
Discussion The DO and WHILE statements provide a means of “loop control” within a
BASIC program. BASIC executes all statements between the DO and the
WHILE as long as the relational expression following the WHILE statement is
true.
You can “nest” additional control loops in a DO - WHILE loop, such as DO - WHILE and
FOR - NEXT. The program example on the right below shows a DO - WHILE loop nested in
another DO - WHILE loop. For more information about nesting, see the section titled “Nesting
Limits” on page 11-25.
10 DO 10 DO : A=A+1 : DO : B=B+1
20 A=A+1 20 PRINT A, B, A*B
30 PRINT A 30 WHILE B<>3
40 WHILE A<4 40 B=0
60 PRINT "DONE" 50 UNTIL A=3
>RUN >RUN
1 1 1 1
2 1 2 2
3 1 3 3
4 2 1 2
DONE 2 2 4
2 3 6
READY – RAM 1 3 1 3
> 3 2 6
. 3 3 9
READY – RAM 1
10-28 Series 30/40 BASIC Guide
DUMP
Displays external or code memory in hex.
Where iexpr1 is the starting address and iexpr2 is the number of bytes to display.
Discussion The DUMP statement provides a handy way to display the contents in hex of a
range of memory. For addresses below 8000h, the DUMP statement prints the
contents of external RAM memory. For addresses at 8000h and above, the
DUMP statement prints the contents of external Flash memory.
>
Commands and Statements 10-29
END
Terminates program execution and returns BASIC to
Command mode.
END
Discussion The END statement terminates program execution. The CONT command
does not operate if the END statement terminates execution; the Workstation
prints CAN’T CONTINUE instead.
READY – RAM 1
>
10-30 Series 30/40 BASIC Guide
ERR
ERL
Discussion ERR and ERL are reserved variable names that are valid only when BASIC
enters an error-handling routine via an “ON ERROR GOTO” statement. ERR
is the error number and ERL is the line number where the error occurred.
Appendix E contains a list of valid error numbers.
>RUN
?56
?0
Error Code 10
Error line number 30/40
56
Commands and Statements 10-31
EXP
Returns “e”(2.7182818) raised to a power.
EXP(expr)
Discussion The EXP statement returns the mathematical constant “e” raised to expr.
>RUN
Enter number 2
7.3890559
READY – RAM 1
>
>PRINT EXP(3)
20.085536
>
10-32 Series 30/40 BASIC Guide
FOR . . . NEXT
Loops a specified number of times.
Where nvar is a numeric variable that initially takes the value of expr1 and increases it by
expr3 until nvar exceeds expr2. If you omit the STEP parameter, the default step value is 1.
If the STEP parameter is negative, then nvar decreases by the value of expr3 until it is less
than expr2.
BASIC adds the STEP value to nvar when it executes the NEXT statement, which means that
every FOR-NEXT loop is executed at least once regardless of expr1 and expr2. Note that the
nvar following NEXT is optional. If you include it, however, it must be the same as the nvar
following FOR.
Discussion The FOR - NEXT loop is a handy way to execute one or more statements a
specific number of times. As indicated in the explanation above, you can
specify a STEP value other than 1 so that the loop either adds or subtracts any
number from the loop variable (nvar) until the loop is finished.
BASIC always executes a FOR - NEXT loop at least once, because it doesn’t check the loop
variable against the loop limit (expr2) until the NEXT statement. You can “nest” control loops
within each other. For example, the statements between a FOR and NEXT can include
additional FOR - NEXT loops as well as other control loops. For more information about
nesting, see the section titled “Nesting Limits” in this chapter.
Note Your program must not exit a FOR - NEXT loop with a
GOTO. The only way your program should terminate a
FOR - NEXT loop is to finish it.
Examples 10 FOR I = 1 TO 2
20 PRINT I
30 NEXT
40 PRINT I
>RUN
1
2
3
This example first sets I to 1 and prints it. Then when BASIC executes the NEXT statement, it
adds the default STEP value of 1 to the variable I and compares the result of 2 to the limit of 2.
Because I is not greater than 2, BASIC returns to line 20 and prints 2, the current value of I.
The next time BASIC reaches the NEXT statement, it changes I to 3, which causes I to exceed
the loop limit; BASIC continues execution at line 40.
Commands and Statements 10-33
10 FOR I = 4 TO 0 STEP -2
20 PRINT I
30 NEXT I
>RUN
4
2
0
FREE
Returns the number of memory bytes available to BASIC.
FREE
Discussion FREE returns the number of program memory bytes available to BASIC. As
you add lines to your program, FREE decreases and heads toward zero. Note
that FREE does not account for the memory your program needs to store
variables; if FREE returns a value of zero, then there is not enough memory for
your program to run.
>
10-34 Series 30/40 BASIC Guide
GOSUB . . . RETURN
Branches to a subroutine.
GOSUB line#
Where line# is the number of the line that BASIC executes next.
Discussion The GOSUB statement causes BASIC to save its current position in the
program and continue program execution at line#. When BASIC executes a
RETURN statement, it recalls its saved position and continues program
execution at the statement immediately following the GOSUB.
The portion of the program beginning at line# and ending with the RETURN
statement is typically called a “subroutine.” Subroutines are useful because the
main program can perform a function from different points in the program
with a single group of statements.
You can “nest” control loops within each other. For example, a subroutine can
call another subroutine; in fact, a subroutine can even call itself. For more
information about nesting, see the section titled “Nesting Limits” in this
chapter.
10 A = 23 : B = 47 10 FOR I=1 TO 3
20 GOSUB 200 20 GOSUB 200
30 END 30 NEXT
200 X = A*B 40 END
210 PRINT X 200 PRINT I,
220 RETURN 210 GOSUB 400
>RUN 220 RETURN
1081 00 PRINT I*I
410 RETURN
READY – RAM 1 >RUN
>
1 1
2 4
3 9
READY – RAM 1
>
Commands and Statements 10-35
GOTO
Continues program execution at a specified line number.
GOTO line#
Where line# is the number of the line that BASIC executes next.
Discussion Unlike the RUN command, the GOTO statement, if executed in the Command
mode, does not erase the variables. However, if you edit a program line and
then execute the GOTO statement, BASIC erases all variables. This is
necessary because the variable storage and the BASIC program reside in the
same memory. Therefore, editing a program can destroy variables.
>RUN
apples
oranges
I skipped peaches
READY – RAM 1
>
Line 30 causes execution of the program to continue at line 50. If line 50 does not exist, the
Workstation prints the message ERROR: UNDEFINED LINE NUMBER.
In Command mode, the following entry causes the program to execute from line number 50.
>GOTO 50
I skipped peaches
READY – RAM 1
>
10-36 Series 30/40 BASIC Guide
HEX$
Returns the string form of a number in hexadecimal format.
HEX$(iexpr)
Where iexpr is a value in the range of 0 to 65,535 and HEX$ returns a string between “0000”
and “FFFF.”
Discussion The HEX$ operator converts the expr to a string where the number is in 4-digit
hexadecimal format. If you want to convert an expression to a decimal format,
you must use STR$ instead.
>RUN
Enter decimal number 165
The hex number 00A5 represents 165
READY – RAM 1
>
>RUN
Enter decimal number 182
005B 182
READY – RAM 1
>
Commands and Statements 10-37
HVAL
Returns the numeric value of a hex string.
HVAL(sexpr)
Where sexpr is a string containing numbers or characters that represent a hexadecimal number
in the range of 0 to 0FFFFh.
Sexpr does not have to begin with a numeric digit and does not have to end
with an “H.”
Examples 10 A$ = "FF"
20 PRINT HVAL(A$)
>RUN
255
10 A$ = "GA"
20 PRINT HVAL(A$)
>RUN
0
10 A$ = "FTF"
20 PRINT HVAL(A$)
>RUN
15
10-38 Series 30/40 BASIC Guide
IBY
Reads from and writes to the indirect internal RAM.
IBY(expr)
Where expr is a number between 0 and 255; IBY returns a number between 0 and 255.
Discussion The IBY operator retrieves or assigns a value to the microprocessor’s internal
indirect RAM memory at address expr. Addresses from 0 to 7Fh are actually
direct internal RAM (also accessible with DBY), while addresses above 7Fh are
indirect only. In any event, BASIC reserves all of this space for itself, so you
must exercise great care in the use of the IBY operator.
>RUN
0 51 74
READY – RAM 1
>
Commands and Statements 10-39
IF . . . THEN . . . ELSE
Directs program flow based on a condition.
Discussion The IF statement tests the value of rexpr. If rexpr is true (i.e., not zero), then
BASIC executes the statement following THEN (and skips the statement
following ELSE). If rexpr is false (i.e., zero), then BASIC executes the
statement or statements following the ELSE. If there is no ELSE, then BASIC
simply continues execution at the next line in the program.
READY – RAM 1
>RUN
?6
X was not 1
READY – RAM 1
>
>RUN
Enter Number 5
5 2
READY – RAM 1
>
10-40 Series 30/40 BASIC Guide
IN#
Switches input to a selected port.
IN# iexpr
Where iexpr is 0 or 1 and selects the port from which the Workstation receives subsequent
input.
Discussion The IN# statement selects the input port for all future INPUT and INPUT$
statements, although individual INPUT and INPUT$ statements can contain
port selections that temporarily override the IN# port selection.
When communicating, the display and keyboard are also considered to be a port. The
following table summarizes the port names and numbers:
For more information about the serial communications ports, consult the
OPEN command.
>RUN
READY – RAM 1
>
Commands and Statements 10-41
INKEY$
Returns a single character, if any, from current input port.
INKEY$ {# port#}
Where port# is 0-1 and selects the port the Workstation checks for a key.
Discussion You can use INKEY$ to test for input on an input port. If you don’t specify the port, then
INKEY$ tests the current input port. If there is no input available, INKEY$ returns a
string of length 0. If there is at least one character available, INKEY$ returns that character
as a one-character string.
When communicating, the display and keyboard are also considered to be a port. The
following table summarizes the port names and numbers:
See the description of the IN# statement for a complete discussion of the
unit’s communications ports.
>RUN
04:24:50
DONE!
READY – RAM 1
>
10-42 Series 30/40 BASIC Guide
INPUT
Requests an entry to a variable.
Where port# is an optional input port number (see the description of the IN# statement for a
complete discussion of the unit’s communications ports). Prompt is an optional message that
BASIC prints to the current output port before accepting input for each var. If there is no
comma preceding the first variable, the Workstation sends a question mark; if there is a
comma, BASIC doesn’t print the question mark.
Discussion BASIC begins execution of the INPUT statement by looking for an optional
input port number. If there is a port number, then BASIC looks for input from
that port only for the duration of the current INPUT statement.
If there is an optional prompt, then BASIC transmits that prompt string to the
currently selected output port. (The PR# statement selects the current output
port.) Then BASIC accepts input to the numeric or string variable(s) listed.
When communicating, the display and keyboard are also considered to be a port. The
following table summarizes the port names and numbers:
Operator input If there is more than one numeric variable in an INPUT statement, the operator
can either make one entry at a time (terminated with carriage return), or make
all entries at once, where the operator enters a comma between each entry. For
string variables, however, the operator must make each entry separately.
If the INPUT statement calls for additional entries, BASIC automatically prints
a question mark before each subsequent entry, even if it didn’t print a question
mark for the first entry.
If your program tries to accept operator input at the bottom line of the display,
the display may scroll up one line when the operator presses [Enter]. This
happens because the Workstation prints a line feed after the carriage return.
To suppress the line feed, OPEN the COM0 without the LF parameter. This
disables printing a line feed after printing a carriage return on the display.
TRY AGAIN If you respond to an INPUT statement with too many or too few items or with
the wrong type of value (numeric where a string is expected, or vice versa),
BASIC prints the message TRY AGAIN. To avoid this message, use the form
INPUT svar, where svar is a string variable, and convert it to a value with the
VAL operator.
Commands and Statements 10-43
Echo suppression Ordinarily, BASIC transmits to the current output port each character it
receives as input; this is usually referred to as “echoing” the input. You can
use the ED parameter in the OPEN command to suppress echoing on specific
ports; refer to the description of the OPEN command for more detail.
INPUT delay timer While BASIC is waiting for INPUT, it cannot do anything else; in fact, even
ON TIME interrupts are disabled during INPUT. Although BASIC ordinarily
waits forever for input, you can use the TD parameter in the OPEN statement
to set up a timer that causes an error when time is up; your error-handling
routine can react to that specific error. See the description of OPEN and ON
ERROR.
Receiving control You should use the INPUT$ function instead of INPUT when you need to
characters accept input without a terminating carriage return or when you simply want to
check the input port and accept any input if it’s there. See the discussion of
INPUT$ for more information.
Keep in mind that INPUT does not accept certain characters in a string. To
receive any of the following characters, except when 0Dh (the [Enter] key)
terminates the INPUT, your program must use the INPUT$( ) function instead.
Keypad ASCII Codes The following table lists the ASCII codes and corresponding characters for
each key of the Workstation’s keypad. This table also lists the many two-
key combination characters that the Workstation supports:
Examples This example shows an input prompt, followed by the input of a numeric
variable. BASIC displays a question mark because no comma precedes the
input variable.
>RUN
ENTER A NUMBER ?144
12
Commands and Statements 10-45
In the next example, the INPUT statement expects two numbers to be input; the comma
suppresses printing of the first question mark, but BASIC prints the question mark in front of
the second input. The first time the program runs, the operator terminates each entry with a
carriage return; the second time, the operator enters both answers at once.
10 INPUT ,A,B
20 PRINT A,B
>RUN
16
?45
16 45
READY – RAM 1
>RUN
16,45
16 45
READY – RAM 1
>
10-46 Series 30/40 BASIC Guide
In the following example, BASIC first prints the prompt string but suppresses the question
mark; then BASIC accepts a string variable.
10 INPUT "NAME:",A$
20 PRINT "HELLO ",A$
>RUN
NAME: CAROLEE
HELLO CAROLEE
READY – RAM 1
>
In the next example, BASIC expects first a string entry and then a numeric entry.
>RUN
Enter your name and age – KRIS
?34
READY – RAM 1
>
In the following example, the console is the current output port. Line 20 selects the keypad as
the input device (#0); notice that because the current output port is the console, the
Workstation echoes the user input to the console, not to the Workstation’s screen. You should
also notice that this command generates a question mark even though a comma precedes the
variable; to eliminate the question mark, you need two commas.
10 CLS
20 INPUT #0, A : REM Inputs from keypad.
>RUN
?563 (input from keypad, echoed to console)
Commands and Statements 10-47
INPUT$
Requests an entry of a specified length.
INPUT$(expr, {# port#})
Where expr is the number of characters expected (if expr = 0, then this function returns all the
characters waiting in the buffer) and port# is an optional input port selection.
Discussion The INPUT$ function returns a string of length expr. If no port number is
specified, BASIC uses the current input port. INPUT$ accepts any characters,
including control characters. INPUT$ does not echo received characters to
the current output port. If the specified length is zero, then INPUT$ returns
all characters that are immediately available.
You can use INPUT$ to test whether input is available. For example, to
test whether a character is available on the keypad, a program could use
INPUT$(0,#0) and test the length of the string returned. (Of course, you
could also use INKEY$ #0 for the same function.)
>RUN
READY – RAM 1
>
10-48 Series 30/40 BASIC Guide
INSTR
Returns the position of a string within another string.
INSTR({iexpr},sexpr1,sexpr2)
Where iexpr is an optional offset to the starting position for the search, and sexpr2 is the
string for which INSTR searches within sexpr1.
Discussion INSTR (in string) returns the starting position of string sexpr2 within string
sexpr1. If there is an optional offset, then the search starts at the nth
character of sexpr1, where n = iexpr. If there is no offset, then INSTR
assumes an offset of 1.
If the string is not found, INSTR returns 0. If the offset exceeds the length of
sexpr1, INSTR returns 0. If the length of sexpr2 is 0, INSTR returns the
offset (or 1 if no offset is specified).
Examples 10 A$ = "Bettendorf"
20 A = INSTR(A$,"tend")
30 PRINT "The position is",A
>RUN
The position is 4
READY – RAM 1
>
10 A$ = "Bettendorf"
20 B$ = "do"
30 A = INSTR(A$,B$)
40 PRINT "The position is",A
>RUN
The position is 7
READY – RAM 1
>
Commands and Statements 10-49
INT
Returns the integer portion of a number.
INT(expr)
Discussion INT strips away the fractional portion of an expression, leaving only the whole
number.
10 A = 45.767
20 PRINT INT(A)
>RUN
45
READY – RAM 1
>
10 A = (12^2) + 3.548
20 PRINT A, INT(A)
>RUN
147.548 147
READY – RAM 1
>
10-50 Series 30/40 BASIC Guide
INV
Returns the inverse.
INV(expr)
Discussion INV returns the “inverse” of the expression. If the expression is 0, then INV
returns a 1; if the expression is not 0, then INV returns 0.
LD@
Retrieves data from external memory and places it in a
variable.
Where iexpr is the starting address of external memory that contains data, and var is the
variable to receive the data. Additional variables that receive their data from consecutive
memory locations are optional.
Discussion In combination with the ST@ command, LD@ provides the ability to save
data in the unit’s memory. ST@ writes variables to memory, while LD@
reads variables from memory.
You can use LD@ to retrieve one or more variables of any type, including
floating point numbers, integers, and strings. You must be careful, of course,
to retrieve variables in the same sequence in which you saved them, or strange
things will happen.
The iexpr parameter is the starting address of the data for var. If there are
more variables following var, then they receive their data from consecutive
memory locations.
Reserving memory In order to save data in memory, you must first find the necessary space. This
space comes from unused Flash EPROM space above your program. To
calculate the first available address, you should use the PLEN command to get
the length of your program and add it to A010h; the result is the first available
address. The maximum address you can use is 0FFFFh.
A location that has not been written has the value 255 (0FFh); you can change
that value to any other value, but the only way to change it back to 255 is to
erase the entire Flash.
10-52 Series 30/40 BASIC Guide
Memory usage Floating point and integer numbers use six bytes of memory. For example, if
your program contains the statement “LD@ 0F000h,A,B%”, then variable A is
retrieved from F000h to F005h, while B% is retrieved from F006h to F00Bh.
ST@ stores strings with their actual length plus 1 byte to hold the length. For
example, if your program stores the string “ABC” at location F000h, the length
byte is at F000h and the characters “ABC” are stored between F001h and
F003h. (ST@ uses only enough memory to store the actual string, not its
maximum length.)
For more information about how BASIC stores variables, consult the
description of the VARPTR statement later in this chapter.
Special VAD variable BASIC has a special variable called VAD that always points one byte past the
last address that the latest LD@ or ST@ used. This is handy to avoid a lot of
“bookkeeping” for programs that store lots of strings, whose lengths can vary.
Examples The example program on the following page saves two variables, S1 and S2, in
Flash memory. When the program starts, it finds the two variables in Flash
and loads them. If the operator then chooses to change them, the program
accepts new values and stores them in memory.
Line 130 establishes address 0F000h as the starting point for permanent variable memory.
This address relies on your program’s length remaining less than 20,000 bytes; you can find
out your program’s length by printing PLEN after you have finished writing your program.
With roughly 4,000 bytes of memory available between 0F000h and 0FFFFh, and with 12 bytes
needed to store the two permanent variables, you can store changes to these variables about 300
times before running out of memory.
Line 140 calls a subroutine starting at line 540 that checks whether the six bytes of memory
starting at address VAD are erased. If they are, then line 150 initializes the permanent
variables to zero and stores them in permanent memory.
If the six bytes of memory at VAD are not erased, then line 160 loads in the variables that are
already stored there. Line 170 calls the subroutine at line 540 again to see if the next six bytes
are erased. If they are, then the program continues at line 180 because it has already found the
last instance in memory of the two permanent variables.
However, if the following bytes are not erased, then the program reloads the variables from the
next higher 12 bytes of memory. This process continues until the program has found the most
recent instance of the two permanent variables.
Commands and Statements 10-53
Lines 180 through 260 allow the operator to choose whether to change the permanent variables
or continue with the program. Lines 280 through 380 allow the operator to change the
variables; before allowing the operator to proceed, however, line 290 tests VAD to see if there
is enough space remaining in permanent memory to store another instance of the variables.
Lines 330 through 370 accept new values for the permanent variables, relying on the
subroutine starting at line 440. This subroutine displays the current value and allows the
operator to press [+] to increase it (line 500), [–] to decrease it (line 510), [↵ ] to enter the new
value (line 490) and [x] to cancel the entry and restore the old value (line 520).
Line 380 concludes by storing the two new values in permanent memory.
10-54 Series 30/40 BASIC Guide
LEFT$
Returns the left part of a string.
LEFT$(sexpr,iexpr)
Where sexpr is any string expression and iexpr is the length of the string to return.
Discussion If iexpr is greater than the number of characters in the string, the entire string
will be returned. If iexpr is zero, a null string (length 0) is returned.
Examples 10 A$ = "Bettendorf"
20 B$ = LEFT$(A$,3)
30 PRINT B$
>RUN
Bet
READY – RAM 1
>
>PRINT LEFT$("Bettendorf",4)
Bett
>
10-56 Series 30/40 BASIC Guide
LEN
Returns the number of characters in a string.
LEN(sexpr)
>RUN
Length of string is 14 characters
Eldridge, Iowa
READY – RAM 1
>
READY – RAM 1
>C$="hello"
>
Commands and Statements 10-57
LET
Assigns the value of an expression to a variable.
Where var is the name of any type of variable that is to be assigned the value of the following
expr.
Discussion As shown in the syntax, LET is an optional word; the equal sign alone is
sufficient for assigning an expression to a variable name.
Examples 10 LET D = 12
20 PRINT D
>RUN
12
>RUN
Oak Street
10-58 Series 30/40 BASIC Guide
LIST
Lists all or part of a program.
Where port# is an optional output port and line# is any valid line number in the program.
Discussion You can use the LIST command to list all or part of your program on the screen of
your PC or of the Workstation (although the latter is not very useful).
Examples >LIST
10 SDIM A$(20) : REM Dimension string
20 A$ = "Ann Arbor, Michigan"
30 L = LEN(A$)
40 PRINT "Length of string is",L,"characters"
50 PRINT A$
READY – RAM 1
>
>LIST 10
10 SDIM A$(20) : REM Dimension string
READY – RAM 1
>
>LIST ,30
10 SDIM A$(20) : REM Dimension string
20 A$ = "Ann Arbor, Michigan"
30 L = LEN(A$)
READY – RAM 1
>
Commands and Statements 10-59
>LIST 20,40
20 A$ = "Ann Arbor, Michigan"
30 L = LEN(A$)
40 PRINT "Length of string is",L,"characters"
READY – RAM 1
>
>LIST 20,
20 A$ = "Ann Arbor, Michigan"
30 L = LEN(A$)
40 PRINT "Length of string is",L,"characters"
50 PRINT A$
READY – RAM 1
>
10-60 Series 30/40 BASIC Guide
LOCATE
Positions the cursor on the display.
Where row# is the line (1 - 2), column# is the display column (1 - 20), and cursor is the style
of cursor displayed (0 = none; 1 = flashing box; and 2 = underline).
Discussion The LOCATE command positions the cursor on the display and optionally
selects the kind of cursor displayed. Any of the parameters may be omitted.
READY - RAM 1
>
The following example places the cursor in column 3, and leaves the row the same.
10 LOCATE ,3
>RUN
READY - RAM 1
>
Commands and Statements 10-61
LOG
Returns the natural logarithm.
LOG(expr)
Discussion The natural logarithm is the logarithm to the base e (2.718281828). LOG and
EXP are inverse functions. Therefore the LOG of EXP(x) is x.
To calculate the logarithm in any other base, use the formula logb(x) = log(x)/log(b).
3.545875
>
10 A = EXP(14)
20 X = LOG(A)
30 PRINT X
>RUN
14
READY – RAM 1
>
>RUN
Enter number 34.67
34.67 3.545875 1.5399547
READY – RAM 1
>
10-62 Series 30/40 BASIC Guide
Where sexpr1 is the string variable; iexpr1 is the new string’s starting point within the current
string; and iexpr2 is the length of the new string.
Discussion On the right side of an equals sign, MID$ returns a string from within another.
The string returned starts at the nth character of sexpr, where n = iexpr1, and
continues for iexpr2 characters. If iexpr1 exceeds the length of sexpr, the
resulting string is null (length = 0).
Examples 10 A$ = "Bettendorf"
20 B$ = MID$(A$,4,4)
30 PRINT B$
>RUN
tend
READY – RAM 1
>
Commands and Statements 10-63
Where svar is a string variable, iexpr1 is an offset into the string and iexpr2 is an optional
length.
Discussion On the left side of an equals sign, MID$ copies the string expression on the
right of the equals sign into the string starting at a specified offset, iexpr1, and
continuing for an optionally specified number of characters, iexpr2. If iexpr1
or iexpr2 equals zero, then svar doesn’t change.
>
10-64 Series 30/40 BASIC Guide
MTOP
Returns or sets the highest memory address available.
MTOP = iexpr
Where iexpr is the highest memory address (plus 1) that is available to your BASIC program.
Discussion MTOP sets or returns the highest memory address (plus 1) available to your
BASIC program. The usual value of MTOP is 32767. If you try to set MTOP
above the highest RAM location physically available, then BASIC issues a
“BAD ARGUMENT ERROR.”
The only reason to reduce MTOP is to use the space in order to save variables in a more
efficient means than BASIC uses. For example, if you needed to save 5,000 integers, BASIC
uses six bytes for each one and would need 30/40,000 bytes. But you could use the XBY()
command to store integers in only two bytes, which means your total memory requirement
would be 10,000 bytes.
>
Commands and Statements 10-65
NEW
Deletes the program currently in memory and clears all
variables.
NEW
Discussion NEW erases the program and clears all variables. You normally use it just
before you download or start writing a new program.
>
10-66 Series 30/40 BASIC Guide
NOT
Returns a 16-bit 1’s complement.
NOT(iexpr)
>RUN
Enter number 34
65501 34
READY – RAM 1
>
Commands and Statements 10-67
ON ERROR GOTO
Enables error handling routine.
Where line# is a line number in the program to which BASIC transfers control when it finds
an error. (Setting line# to 0 disables error handling.)
When BASIC enters the error routine, it sets up the special variables ERR and ERL to hold the
error number and line number of the error; in any other situation, the status of these variables
is invalid. In order to resume program execution, the error handler must exit with a RESUME
statement. See the description of RESUME for more information.
If the error handling routine terminates program execution (with the STOP, END, or ON
ERROR GOTO 0 statement), BASIC immediately prints the error. If an error occurs within
the error handler, BASIC terminates program execution and reports the error.
Some communications errors can occur asynchronously, which means that ERL may not be
valid. For example, if a receive buffer overflows, ERR will be correct but ERL will be the
number of the line that the Workstation was executing when the overflow occurred. For an
example, see the note under the description of the ERR and ERL statements earlier in this
chapter. See the error message listing in the Appendix for a list of the asynchronous
communications errors.
BASIC does not report asynchronous communications errors that occur during the error-
handling routine. Your routine must RESUME before your program can detect that type of
error.
During debugging, you may want to set up your error-handling routine to print a status
message to the console and then immediately terminate program execution. In this case, most
of your status message may be lost, because BASIC clears its communications buffers before
printing an error message. In other words, BASIC erases any part of the message that still
remains in the buffer. To ensure that the buffer empties, you may want to add a FOR – NEXT
loop to idle a few seconds before ending the program.
You must be careful that your error-handler RESUMEs without disrupting control loops such
as GOSUB – RETURN or FOR – NEXT. For example, if your error handler RESUMES
outside a FOR – NEXT loop, the system's internal control stack will be left out of whack.
10-68 Series 30/40 BASIC Guide
>RUN
?34
100 divided by 34 equals 2.9411765
?0
You have attempted to divide by zero!
We have substituted a 1 for your input
100 divided by 1 equals 100
?
Commands and Statements 10-69
ON . . . GOSUB
Calls one of a list of subroutines.
Where expr is an expression that BASIC automatically rounds to an integer; BASIC passes
control to the nth line#, where n = expr + 1.
Discussion The value of the expression determines which line number in the list is the
starting line of the subroutine that BASIC calls. For example, if the expression
is 0, BASIC calls the first subroutine in the list. BASIC ignores any fractional
part of the expression. The subroutine must end with a RETURN, at which
point BASIC passes control to the next statement following the ON GOSUB
statement.
>RUN
Enter number 2.5
The answer to A was 2
DONE
READY – RAM 1
>
10-70 Series 30/40 BASIC Guide
ON . . . GOTO
Branches to one of a list of lines.
Where expr is an expression that BASIC rounds to an integer; BASIC passes control to the nth
line#, where n = expr + 1.
Discussion The value of the expression determines which line number in the list to which
BASIC transfers control. For example, if the expression is 0, BASIC goes to
the first line number in the list. BASIC ignores any fractional part of the
expression.
.
Examples 10 INPUT "Enter number ",A
20 IF A >= 4 THEN 40
30 ON A GOTO 100, 200, 30/400, 400
40 PRINT "You blew it, Jack"
50 END
100 PRINT "The answer to A was 0"
110 GOTO 10
200 PRINT "The answer to A was 1"
210 GOTO 10
30 PRINT "The answer to A was 2"
310 GOTO 10
400 PRINT "The answer to A was 3"
410 GOTO 10
>RUN
Enter number 2.5
The answer to A was 2
Enter number 4
You blew it, Jack
READY – RAM 1
>
Commands and Statements 10-71
ON TIME = . . . GOSUB
Sets up time-based interrupt handler.
Where expr is an integer setpoint for the timer; line# is the line number of the subroutine that
handles timer interrupts.
Discussion The ON TIME statement tells BASIC to call a subroutine after a specified
period of time. This “interrupt” capability makes it easy for you to set up
events to occur on a regular schedule. After BASIC executes an ON TIME
statement, it must then execute a CLOCK1 statement in order to reset the timer
and enable the ON TIME interrupt.
After executing the CLOCK1 statement, BASIC continually monitors the status of the timer,
which is stored in a special variable called TIME. When TIME is equal to or greater than
expr, BASIC calls the subroutine beginning at line#. The best resolution possible from the
timer is 0.005 seconds, although you must plan on a “latency” or delay in handling the
interrupt until BASIC completes the statement it is currently executing. This latency could be
a very long time if BASIC happens to be in the middle of an INPUT statement when the timer
times out.
Note If you want to use the ON TIME capability and still have
the capability of using the INPUT statement, you should
write a subroutine that emulates the INPUT statement. You
can use INKEY$ #0 or INPUT$(0,#0) to test for characters
received from the keypad and build response strings with
some additional decoding logic
.
If you want BASIC to execute the timer subroutine on a regular schedule, your
subroutine would have to reset TIME either at the beginning or the end of the
routine, depending on your requirements, with another CLOCK1 statement.
If you want your timer subroutine to cancel further timer interrupts, your
subroutine should contain a CLOCK0 statement. The subroutine can also
change the timer setpoint with another ON TIME statement. In any event,
your timer subroutine must end with a RETI statement, not a RETURN
statement.
Examples This demonstration calls the timer subroutine at 1.105 second intervals:
This demonstration calls the subroutine every second with virtually no accumulation of error:
OPEN COM
Declares a port’s communication parameters.
Where port is the hardware port designation followed by any combination and sequence of
optional parameters as specified in the table below, followed by an optional designation of an
alias. A full discussion of each parameter follows the table.
Because the data between quotation marks is actually a string, you can use a string variable.
For example, OPEN A$ is a valid statement, provided A$ is in the correct format.
The display and keyboard are also considered to be a port; the following table summarizes the
port names and numbers:
There are three “default” columns in the following table because there are three situations
under which default conditions can occur:
Initial Default Refers to the status of the parameter the first time you power up.
OPEN Default Refers to the status of the parameter if you omit it. For example,
omitting the “TD” parameter sets up the port as if you entered
“TD100”; the only way to disable the TD parameter is to use “TD0”
in your OPEN statement.
Param Default Refers to the default value of the parameter if you omit the optional
number that follows the letters.
Alias The alias is an optional parameter that allows the software to refer to the port
by a different number. For example, OPEN “COM1:” AS #2 sets up COM1 as
port number 2. All further references to port 2, such as PR#2, IN#2, PRINT #2
and INPUT #2, refer to COM1.
The alias capability is not very useful for the Series 30/40 Workstation, because it has only one
communications port. We suggest that you omit using the alias.
AR; Auto-Repeat This parameter enables the auto-repeat capability on the keypad, which allows
Enable the operator to hold a key down instead of pressing it repeatedly. Optionally
following this parameter is the delay between pressing the key and the first
repetition. The resolution of the delay time is 50 milliseconds.
For example, the parameter AR10 enables the auto-repeat function and configures the
Workstation to start repeating after 500 milliseconds (50 milliseconds * 10). The RD
parameter sets the speed of subsequent repeats; you can change the time between repeats from
the default value of 100 milliseconds.
Warning You should not enable the auto-repeat function if there are
any keys that cause your machinery to perform a potentially
hazardous control operation.
CE; [Ctrl]-C The CE parameter enables the Workstation to react to an ASCII character code
Enable of 3 as an interrupt. On most computers, you can generate this code by holding
down the [Ctrl] key while pressing the letter “C”; on the Workstation’s keypad,
you can generate this code by holding down [F1] and [↵ ] at the same time.
BASIC handles a [Ctrl]-C interrupt as an error: it either terminates program execution or goes
to the routine specified by an ON ERROR statement.
CL; Enable The CL parameter affects only the operation of the Workstation’s display; if
CRLF you include the CL parameter when opening COM0, then BASIC
automatically moves the cursor to the first position of the next line after it
prints a character in the last column.
If the cursor is already on the bottom row of the display, then the action of the screen depends
on the WA and SC parameters. If the WA parameter is included, the cursor moves to the top
line; if the SC parameter is included, BASIC moves the bottom line to the top, clears the
bottom line, and leaves the cursor on the bottom line.
Commands and Statements 10-75
CR; Enable CR The CR parameter affects only the operation of the Workstation’s display; if
you include the CR parameter when opening COM0, then BASIC
automatically moves the cursor to the first position of the current line after it
prints a character in the last column.
CS; Wait for CTS If you specify the CS parameter, then the Workstation requires the port’s CTS
input to be asserted before transmitting. This is a type of “hardware
handshaking” where you connect a control line from another device that
indicates “ready to receive” to the “Clear To Send” input of the port.
This capability is useful when the port is transmitting to a device that cannot
accept data at full speed. If the device has a hardware handshaking capability
for its receiver, then you can wire its output to the port’s CTS input.
When your program tries to transmit, the Workstation tests the CTS input; if CTS is not
asserted, the Workstation starts a timer and continues to test CTS. If CTS fails to be asserted
within the time limit, then BASIC issues a timeout error.
Optionally following the CS parameter is the setpoint for the timer; the resolution of this timer
is 50 milliseconds. If you omit the timer setpoint, BASIC uses the default value of 100, which
is 5 seconds. If you specify a setpoint of 0, then BASIC waits forever for CTS and never
generates an error.
Data You can specify the number of bits in each data byte as 7 or 8; the default
value is 8. You must select the data size to match the data size of the device
you connect to the port. If you have a choice, we recommend you set the
device to a data size of 8 bits.
Note If you set COM1 to 7 data bits and no parity, then you must set
the stop bits of the device connected to COM1 to 2, regardless
of the number of stop bits you set for COM1.
ED; Echo The ED parameter indicates that the Workstation should not “echo” characters
Disable received on an INPUT statement.
Normally, the Workstation re-transmits every character to the current output port that it
receives in response to an INPUT statement. This is very nice when receiving input from a
person, but can be a problem when the port is receiving input from another intelligent device.
As an example, suppose the port is receiving data from a motion control system. In a typical
exchange, the port may send a command to the motion controller to send back its status. The
Workstation would then use an INPUT statement to receive this status information from the
port.
With echoing enabled, the Workstation would receive the status information and send it back
out to the motion controller (or whatever the current output device is). With echoing disabled,
the Workstation would simply receive the status information.
10-76 Series 30/40 BASIC Guide
IB; Enable The IB parameter indicates that the Workstation should send and receive
Buffers characters using 255-character buffers instead of 1-character buffers. The
differences in operation are summarized in the table below:
Transmit The program can place up to 255 If the port is actively transmitting,
characters in a buffer (using the PRINT program execution halts while the
statement); the Workstation transmits Workstation transmits each character to
from the buffer while continuing to be PRINTed.
execute the program.
However, if handshaking has made the
If the program tries to PRINT when the port inactive, BASIC returns a BUFFER
buffer is already full, the Workstation's FULL error.
response depends on the status of the
port. If the port is actively transmitting,
then program execution stops until the
buffer is sufficiently empty for the
remaining characters.
You can use a special CALL to retrieve the current status of a buffer. After the
CALL, your program must POP the status of the buffer into a variable (for
example, CALL 40 : POP A returns A equal to the number of characters
remaining in the receive buffer of the first port):
CALL Function
40 #1 receive
41 #1 transmit
In many applications, buffered communications can be a problem. For
example, if the port is connected to a device that “echoes,” then that device
sends back to the port every character it receives. With no buffers, however,
the port loses those characters, except perhaps the first character, which the
user program must discard.
IC; IBM- Inclusion of this parameter when opening COM0 causes the Workstation to
Compatible display characters using the same ASCII codes as the IBM PC’s “multilingual”
code page, which is code page 850.
The Workstation’s display supports only a few of the foreign language characters, so the IC
parameter is not particularly helpful.
LF; Line Feed The LF parameter indicates that the Workstation should send a “line feed”
Enable character after every “carriage return” character.
After the first power-up, this parameter comes up enabled; in an OPEN
statement, however, the default is disabled. In order to enable this capability in
an OPEN statement, you must include the LF code.
The LF parameter is useful only when the port is transmitting to a relatively “dumb” device
like a terminal. Many intelligent devices accept a carriage return as a terminating character
and reject the line feed as an error.
LL; Set Line You can specify the maximum length of a line with the LL parameter followed
Length by the line length. When BASIC transmits (PRINTs) a character to that
maximum position, it automatically transmits a carriage return. To disable this
feature, you should simply omit this parameter. The LL parameter is primarily
useful when transmitting to a printer.
Parity You can select N for no parity, E for even parity, or O for odd parity. You
must choose a parity selection that matches the device connected to the port. If
you select even or odd parity and the port receives a character with the wrong
parity, it generates an error.
If you have a choice, we recommend you select E or O, but then you’ll probably need a routine
to handle any parity errors.
Port Every OPEN command must contain a designation for the hardware port you
are opening. The previous table lists the valid hardware ports.
PS; Select Parity The PS parameter specifies the ASCII code of the character that the
Character Workstation substitutes for any characters it receives with a parity error. In
other words, the Workstation can translate a parity error into another character
instead of reporting the error.
For example, the parameter PS126 causes the Workstation to substitute the character “~” in
place of any characters it receives with an error in parity.
Rate You can specify a baud rate for the serial ports; the previous table lists the baud
rates that the Workstation supports.
RD; Set Repeat The RD parameter enables the keypad’s auto-repeat capability and sets the time
Rate between the second and subsequent repeats. The resolution of the time delay is
50 milliseconds.
You should see the description of the AR parameter for more information about
the auto-repeat capability.
10-78 Series 30/40 BASIC Guide
RH; Receive The RH parameter enables “hardware handshaking” on the port’s receiver,
Handshake which is useful when your program is unable to receive from another device at
full speed.
Enable
The RH parameter causes the port to assert its RTS output whenever its receive
buffer is less than 3/4 full. If you connect that RTS output to the CTS input of
another device, the other device will transmit only when the Workstation is
ready to receive.
As a practical matter, when you use the RH parameter you should also select buffered
communications with the IB parameter.
RN; RTS Never The RN parameter causes the port to leave its RTS output off. This parameter
On allows you to use CALL 30/40 effectively, because any other choice for RTS
handshaking renders CALL 30/40 ineffective.
RO; RTS On at The RO parameter causes the port to assert its RTS output at the start of
Start transmitting and to leave RTS asserted indefinitely. You can use CALL 30/40
to turn off RTS later.
RS; RTS On The RS parameter causes the port to assert RTS only when it has characters to
During Transmit transmit. If the OPEN statement omits the RH, RO, and RS parameters, then
RTS remains asserted all the time.
You must include the RS parameter when you are using the port in an RS-422/485 application
because RTS also enables the transmitter itself. When RTS is not asserted, the transmitter
turns off, which allows another transmitter to communicate on the same wires.
RX; XON/XOFF The RX parameter enables “software handshaking” using the XON/XOFF
on Receive ([Ctrl]-S/[Ctrl]-Q) protocol when receiving.
When the Workstation’s receive buffer becomes 75% full, the Workstation
transmits an “XOFF” character to the transmitting device, which should stop
sending. When the Workstation’s receive buffer is emptied to less than 50%
full, the Workstation sends an “XON” character to the transmitting device to
re-start communications.
Your program should not enable RX if the other device does not support XON/XOFF, or the
Workstation may operate in an unexpected manner.
As a practical matter, when you use the RX parameter you should also select buffered
communications with the IB parameter.
SC; Scroll The SC parameter enables the Workstation’s display to scroll when printing
Enable past the last character on the screen or before the first character. In most
applications, you should include the CL parameter as well.
Stop You can specify the number of stop bits that the port transmits after each data
byte as 1 or 2; the default value is 1. You must select the data size to match the
data size of the device you connect to the port. If you have a choice, we
recommend you set the device’s stop bits to 1. When you set the number of
data bits for COM1 to 7 and set its parity to none, then you must set the
number of stop bits for COM1 to 2, because COM1 doesn’t support the
combination 7,N,1.
TD; Set Input When you open a port with the TD parameter, BASIC starts a 5-second timer
Delay at the beginning of an INPUT or INPUT$ statement and generates an error if
no input occurs during the time period.
Commands and Statements 10-79
You can optionally specify a different timer setpoint following TD. The unit of measure is 50
milliseconds; for example, “TD10” tells the Workstation to wait for input no longer than 500
milliseconds (0.5 second) before issuing an error message.
This capability is useful to detect a fault without leaving the program “hung” while waiting for
input. If a time delay is enabled, then the Workstation can handle a “time-out” error with an
error-handling routine accessed by an ON ERROR statement.
TX; XON/XOFF The TX parameter configures the port for “software handshaking” using the
for Transmit XON/XOFF ([Ctrl]-S/[Ctrl]-Q) protocol when transmitting. After receiving an
XOFF, the Workstation starts a 5-second timer; if it times out before the
Workstation receives an XON, the Workstation generates an error.
You can optionally specify a different timer setpoint following TX. The unit of measure is 50
milliseconds; for example, “TX10” tells the Workstation to wait for XON no longer than 500
milliseconds (0.5 second) before issuing an error message.
Your program should disable the TX capability if the transmitting device does not support the
XON/XOFF protocol. This is especially important if the transmitting device is sending
“binary” data where an XON or XOFF character could be part of the data stream.
WA; Wrap When you OPEN COM0 with the WA parameter, the Workstation “wraps
Enable around” to the first position on the screen after it prints to the last position. In
most applications, you should include the CL parameter as well.
>RUN
READY – RAM 1
>
10-80 Series 30/40 BASIC Guide
Where port# is an optional port number to print to and expr is an expression of any type to
print.
Discussion The PH0. and PH1. statements operate just like PRINT, except that they print
all numbers in hexadecimal format instead of floating point format. Consult
the description of PRINT for details.
The PH1. statement prints hex numbers in 4-digit format followed by the letter
H. The PH0. statement does not print leading zeroes unless the number is less
than 10h.
>
>PH0.(66)
42H
>PH1.(66)
0042H
>PH0.(1000)
3E8H
>PH1.(1000)
03E8H
>
Commands and Statements 10-81
PI
Equals π (3.1415926).
PI
>RUN
Enter radius of circle 2
The area of the circle is 12.56637
READY – RAM 1
>
10-82 Series 30/40 BASIC Guide
PLEN
Returns the length of your program.
PLEN
Discussion PLEN (Program Length) returns the length of your program in number of
bytes.
Examples 10 INPUT A$
20 A = LEN(A$)
30 PRINT A
40 PRINT PLEN
>RUN
?Circle tap
10
34
READY – RAM 1
>
Commands and Statements 10-83
POP
Equates a variable to the number at the top of the argument
stack.
POP var
Discussion POP sets var to the number at the top of the argument stack. See the description
of PUSH for more information about the stack.
Some built-in CALLs return a result on the argument stack that your program
must remove with the POP command. If there is no data on the argument stack,
then the Workstation issues an A_STACK error.
>RUN
Port #1 receive buffer size = 0
READY – RAM 1
>
10-84 Series 30/40 BASIC Guide
POS
Returns the column number of the screen display’s cursor.
POS
Discussion The POS statement returns the column number occupied by the cursor on the
display. The column number varies between 1 and 20.
Examples The following program continuously updates the time on the display
independently of the rest of the program. Line 100 saves the current cursor
position so that line 120 can restore it later.
10 CLS : PR# 0
20 ON TIME = 1 GOSUB 100 : CLOCK 1
30 FOR I = 1 to 99999
40 PRINT USING "#####";I;CR;
50 NEXT
60 GOTO 30/40
100 RS = CSRLIN : CS = POS
110 LOCATE 2,5 : PRINT TIME$;
120 LOCATE RS,CS
130 CLOCK 1 : RETI
Commands and Statements 10-85
PR#
Switches output to specified port.
PR# iexpr
Discussion PR# directs all output from PRINT statements to a specified port, although a
PRINT statement can contain a port selection that temporarily overrides the
PR# port selection.
The display and keyboard are also considered to be a port; the following table summarizes the
port names and numbers:
Examples 10 CLS
20 PR#0: REM Select Workstation’s display for
printing
30 PRINT "This is the Workstation’s display"
40 PR#1: PRINT "This is on the computer screen"
>RUN
This is on the computer screen
PRINT
Prints to an output device.
Where port# is an optional port number and expr is any valid numeric and/or string
expression. Multiple expressions must be separated by a comma or semicolon.
Discussion You can use the PRINT statement to print any combination of characters,
strings, and numbers to the display or to the communications ports. The
following discussion describes the various options of this powerful command in
detail.
Spaces between The PRINT statement can print one or more expressions, where each is
expressions separated by a comma or semicolon. The comma inserts a space between each
expression, while the semicolon inserts no spaces. (Note that BASIC handles
commas differently than most BASICs, which use the comma as an implied
tab.)
Suppressing the At its conclusion, the PRINT statement sends a carriage return to the current
carriage return/line output device. By default, the Workstation sends a line feed after a carriage
feed return, although you can use the OPEN statement to defeat this feature (just
omit “LF” from the parameter list). You can defeat printing the carriage return
by ending the statement with a semicolon or a comma.
Printing numbers BASIC prints positive floating point numbers with a leading space and
negative floating point numbers with a leading minus sign. The only way to
eliminate the leading space is to convert the number to a string with the STR$
statement. You can adjust the output format of floating point numbers with the
USING statement.
BASIC prints hexadecimal numbers without leading or trailing spaces, but you
must use the alternative print statements PH0. or PH1.
Print USING format A PRINT statement can contain one or more USING statements that apply only
to the following floating point numbers in the current statement. (However, if
USING appears alone in a PRINT statement, then that output format becomes
the default format for all subsequent PRINT statements; consult the description
of PRINT USING next in this chapter for more information.)
Commands and Statements 10-87
Printing multiple BASIC can print multiple spaces using the SPC operator; for example,
spaces or tabs SPC(10) tells the Workstation to print ten spaces. Don’t forget, however, that
if the SPC operator is both preceded and followed by a comma, BASIC prints a
total of 12 spaces.
BASIC can also skip to another column using the TAB operator. For example,
TAB(10) tells the Workstation to print enough spaces to move the cursor to
column 10 (unless the cursor is already past column 10).
Printing strings The Workstation can print any character or group of characters if they are
enclosed in double quotation marks. In order to print a double quotation mark
or “control” character with an ASCII value of less than 20h, however, you must
use the CHR$ function. For example, to print a double quotation mark, your
program would read “PRINT CHR$(34).”
Output port The output of the PRINT statement goes to the device selected by the most
recent PR# statement. However, you can override this selection for the current
PRINT statement by specifying a port number first. For example, PRINT #0,
“TEST” sends the string “TEST” to the Workstation’s display.
The display and keyboard are also considered to be a port; the following table summarizes the
port names and numbers:
Examples >PRINT 10 * 3
30
>RUN
Enter temperature 78
The temperature is 78degrees
The temperature is 78 degrees
The temperature is 78 degrees
The temperature is 78degrees
READY – RAM 1
>
10-88 Series 30/40 BASIC Guide
>RUN
ENTER NUMBER - 12
ENTER SECOND NUMBER - 44
56 528
READY – RAM 1
>
PRINT USING
Sets up format for printing numbers.
Where sexpr specifies the format of printed variables; “0” specifies the general floating point
format.
Discussion The format string that follows the USING statement specifies to BASIC the
output format for floating point numbers. The default format is “0”, which
means that BASIC prints floating point numbers according to its standard
rules. The # symbol indicates a character position; for example, the format
string “##.##” indicates that BASIC should print two digits to the left of the
decimal point and two digits to the right. If you use the letter “Z” in place of
the “#” anywhere in the format string, then BASIC prints the leading zeroes.
The format string can include no more than eight “#” or “Z” symbols, because
BASIC stores numbers with only 8 significant digits.
If a number is too big to print according to the format statement, then BASIC
prints a question mark and then prints the number in the general floating
point format.
Floating point format The printed appearance of a number in the floating point format depends on
(USING “0”) the size of the number. If the number is between 0.000001 and 10,000,000,
then BASIC prints it just as it appears here. BASIC prints any number
outside that range in exponential format, whose general format is “n Ee”
where “n” is up to 8 significant digits of the number and “e” is the exponent
of the number.
BASIC prints positive numbers with a leading space and negative numbers with a leading
minus sign. To eliminate the leading space, your program must first convert the number to a
string with the STR$ command.
Commands and Statements 10-89
A PRINT statement that contains only a USING statement (followed by the format string, of
course) does not actually print; instead, it simply establishes the format as a “global” format
that applies to all subsequent PRINT statements. A PRINT statement can override the global
format by including a USING statement that applies only to the remainder of the PRINT
statement.
Examples The comma following the format statement prints a space before printing the
number; to suppress this, you should use a semicolon instead of a number.
Line 70 shows how to use the STR$ command to eliminate the leading space
for positive numbers.
10 PRINT PI
20 PRINT USING "###.##z", PI
30 PRINT USING "#.#######", PI
40 A$ = "#.##" : PRINT USING A$; PI
50 PRINT USING "##.##",PI*100
60 PRINT PI * 10 ^ 10
70 PRINT STR$(PI)
>RUN
3.1415926
003.141
3.1415926
3.14
? 314.15926
3.1415926 E+10
3.1415926
READY – RAM 1
>
10-90 Series 30/40 BASIC Guide
PUSH
Places an expression on the argument stack.
PUSH aexpr
Where aexpr is an integer or floating point number and is pushed onto the argument stack.
Discussion BASIC maintains a “stack” where it saves the intermediate results of various
calculations. The PUSH command simply evaluates the subsequent numeric
expression and leaves the result on the stack.
BASIC does not provide any standard statements that require a preceding
PUSH. However, BASIC supports some undocumented CALLs that do require
a PUSH.
RAM
Selects a program for editing or inserts a copy of a program.
RAM prog#
or
RAM prog1 = RAM prog2
Where prog#, prog1, and prog2 are numbers less than 256, and prog2 exists.
Discussion When you use the command RAMx by itself, it selects program x for editing. If
program x doesn’t exist, then BASIC creates a new empty program at the end
of the directory. For example, if you type RAM 5 when there are only three
valid programs in memory, BASIC creates a new, empty program at RAM 4
and selects RAM 4 for editing.
To insert a copy of one program before another, you would use the command format
RAMx = RAMy, which inserts a copy of program y before program x. If program x doesn’t
exist, then BASIC copies program y to the end of the directory. For example, if you type RAM
5 = RAM 1 when there are only three valid programs in memory, then BASIC makes a copy of
RAM 1 at RAM 4.
Commands and Statements 10-91
READY - RAM 2
>DIR
RAM 1 (1000H,0020H) - PROGRAM 1
RAM 2 (1020H,0020H) - PROGRAM 2
READY - RAM 2
>RAM 4
READY - RAM 3
>DIR
RAM 1 (1020H,0020H) - PROGRAM 1
RAM 2 (1040H,0020H) - PROGRAM 2
RAM 3 (1060H,0005H) -
READY - RAM 3
>RAM1 = RAM 2
READY - RAM 3
>DIR
RAM 1 (1000H,0020H) - PROGRAM 2
RAM 2 (1020H,0020H) - PROGRAM 1
RAM 3 (1040H,0020H) - PROGRAM 2
RAM 4 (1060H,0005H) -
READY – RAM 3
>
10-92 Series 30/40 BASIC Guide
REACT
Specifies the start-up action after reset.
Where par is a parameter (R, RAMx, C or P) that alters the Workstation’s start-up actions.
Discussion REACT (REset ACTion) allows you to set up the Workstation’s start-up
sequence. Typically, you use this command to make the Workstation
automatically RUN its program after reset.
Each REACT command replaces any previous REACT commands, except that the system
remembers REACT Cx commands. You can cancel all but REACT Cx by entering the
REACT command followed by no parameters.
If no parameters are listed, then the Workstation performs its default functions. The default
sequence after reset is:
1. Go to the Command mode.
2. Select the default port as the console port (COM1).
Note If you want your program to auto-start, then you must use the
REACT command before you copy your program to ROM.
R; Run Program This parameter causes the Workstation to automatically run a program after
power-up.
READY – RAM 1
>REACT R
READY – RAM 1
>ROM = RAM 1
READY - RAM1
>
C {#}; Console This parameter tells the Workstation which port is the console port. For
example, REACT C2 tells the Workstation to use port #2 as the console. You
should be careful, however, because this port selection refers to the alias and
not the actual hardware port number.
P; Protect When you use it with the R parameter, the P parameter locks BASIC in the run
mode; if program execution terminates for any reason, BASIC simply re-runs
the program.
READ
Reads values from a DATA statement and assigns them to
variables.
Discussion The READ statement gets its data from DATA statements. Every time
BASIC READs a data, it points to the next item of data.
Unlike most BASICs, you must enclose DATA strings in quotation marks,
as shown in the second example below.
Examples 10 FOR I = 1 TO 6
20 READ A(I)
30 PRINT A(I), : NEXT
40 DATA 23, 56, 125, 400, 530, 409
>RUN
23 56 125 400 530 409
READY – RAM 1
>
If insufficient data exists to fill the list, an ERROR: NO DATA message is issued. To re-read
DATA statements from the beginning, use the RESTORE statement.
10 FOR I = 1 TO 8
20 READ A$(I)
30 PRINT A$(I),
40 IF I = 6 THEN RESTORE
50 NEXT
60 DATA "ABC","DEF","GHI","JKL","MNO","PQR"
>RUN
ABC DEF GHI JKL MNO PQR ABC DEF
READY – RAM 1
>
10-94 Series 30/40 BASIC Guide
REM
Indicates that the rest of the line is only a remark.
REM {remark}
If you write your program in a word processor, you should consider including
REM statements without line numbers. When you download your program to
the Workstation, the REM statements don’t take any program memory because
the Workstation doesn’t save them.
>RUN
Enter first number 45
Enter second number 4
180
49
11.25
41
4100625
Commands and Statements 10-95
RENUM
Renumbers all or part of a program.
RENUM {new}{,inc}{,start}{,end}
Where new is the first new line number, inc is the amount by which each subsequent line
number will be increased, start is the old line number of the first line to renumber, and end is
the old line number of the last line to renumber. The default parameters are 100,10,0,65535; if
you omit any parameter, BASIC uses its default.
Discussion The RENUM command is a handy way to renumber your program. You can
renumber all or part of your program, depending on whether you specify any
parameters.
You cannot use RENUM to re-arrange lines in your program. For example, you cannot
renumber lines 100 through 199 so that they appear after lines 200 through 299; if you try,
BASIC issues a BAD ARGUMENT error instead.
If the system runs out of memory while renumbering, it prints the error message OUT OF
MEMORY. This normally would happen only if you have very little memory remaining and
insufficient space remains for BASIC to store a table that holds the old line numbers and their
corresponding new line numbers.
Note In very rare cases, it’s possible for BASIC to run out of
memory while actually renumbering. This could happen if
free memory is almost gone and a new line number makes a
line longer than it used to be. For example, if GOTO 10
becomes GOTO 1000, then the line becomes two bytes
longer. If there is insufficient free memory to store the
longer line, BASIC issues an error message and stops
renumbering in the middle, which leaves your program
scrambled beyond use.
Examples >LIST
10 PRINT "LINE 10" : ON ERROR GOTO 40
20 PRINT "LINE 20" : GOTO 30
30 PRINT "LINE 30" : END
40 RESUME 40
READY - RAM 1
>RENUM
>LIST
100 PRINT "LINE 10" : ON ERROR GOTO 130/40
110 PRINT "LINE 20" : GOTO 120
120 PRINT "LINE 30" : END
130 RESUME 120
READY - RAM 1
>
10-96 Series 30/40 BASIC Guide
RESTORE
Resets the pointer to the DATA items.
RESTORE {line#}
If you specify an optional line number after RESTORE, then BASIC resets the pointer to the
first DATA statement at or following the line number.
>RUN
1 2 3 4
1 2 3 4
3 4 5 6
READY - RAM 1
>
Commands and Statements 10-97
RESUME
Continues program execution at the end of error-handling.
RESUME {line#}
or
RESUME {NEXT}
Where line# is the line number where BASIC continues program execution at the conclusion of
the error-handling routine.
Discussion If you use the ON ERROR capability, your error-handling routine must
terminate with a RESUME command in order to continue program execution.
If there is no line#, BASIC continues execution where the error occurred; if RESUME is
followed by NEXT, BASIC continues execution at the statement following the statement that
caused the error.
>RUN
Enter first number 45
Enter second number 0
0
45
Can't divide by zero
45
1
READY – RAM 1
>
10-98 Series 30/40 BASIC Guide
RETI
Returns from ON TIME handling routine.
RETI
Discussion The RETI statement terminates an ON TIME service routine. The RETI
statement does the same thing as RETURN except that it also clears a software
interrupt flag so BASIC can handle subsequent interrupts.
>RUN
Waiting for interrupt
Interrupt evoked at 5.02 seconds
Interrupt evoked at 5.02 seconds
>RUN
Interrupt evoked at 5.02 seconds
Waiting for interrupt
The above program does not work properly (only one interrupt executed) because the RETURN
statement was used instead of the RETI statement.
Commands and Statements 10-99
RETURN
Returns from a subroutine.
RETURN
Examples 10 FOR I = 1 TO 10
20 IF I = 6 THEN GOSUB 100
30 PRINT I
40 NEXT
50 PRINT : "The job is finished"
60 END
100 PRINT "We are at number 6 now"
110 RETURN
>RUN
1
2
3
4
5
We are at number 6 now
6
7
8
9
10
The job is finished
READY – RAM 1
>
10-100 Series 30/40 BASIC Guide
RIGHT$
Returns the rightmost characters of a string.
RIGHT$(sexpr,iexpr)
Where sexpr is a string and iexpr is the number of characters in the result.
Discussion If iexpr is greater than the number of characters in the string, the entire string
is returned. If iexpr is zero, a null string (length 0) is returned.
Examples 10 A$ = "Phoenix"
20 B$ = RIGHT$(A$,3)
30 PRINT B$
>RUN
nix
READY – RAM 1
>
>PRINT RIGHT$("Phoenix",3)
nix
>
Commands and Statements 10-101
RND
Returns a random number between 0 and 1.
RND
Discussion The RND statement returns a random number between 0.0000000 and
0.9999999. The Workstation always generates random numbers in the same
sequence after a power-up.
The random number “seed” is a 16-bit binary number, and the random
numbers that the Workstation generates are in the range of 0/65535 to
65535/65535.
Examples 10 FOR I = 1 TO 5
20 PRINT INT(RND*100)
30 NEXT
>RUN
57
88
95
3
36
READY – RAM 1
>
10-102 Series 30/40 BASIC Guide
ROM
Copies a program in RAM to permanent memory in Flash.
READY - RAM 1
>REACT R
READY - RAM 1
>ROM = RAM 1
READY - RAM 1
>DIR
RAM 1 (1000H,0020H) - PROGRAM 1
ROM 1 (A000H,0020H) - PROGRAM 1
READY - RAM 1
>
Commands and Statements 10-103
RUN
Starts execution of a program.
Where line# is the line number at which to begin execution and prog# specifies which
program to run.
Discussion RUN clears all variables and starts program execution. You can optionally
specify a line number after RUN in order to begin execution with a line other
than the first, or you can specify a program number to run a program other
than the current. The valid combinations follow:
Examples 10 PRINT 1,
20 PRINT 2,
30 PRINT 3
>RUN
1 2 3
READY – RAM 1
>RUN 20
2 3
READY - RAM 1
>
10-104 Series 30/40 BASIC Guide
SDIM
Sets the maximum length of a string.
SDIM var$(iexpr)
or
SDIM = iexpr
Where var is the string name and iexpr is the length of the string (between 1 and 254)
Discussion The default length of a string variable is 10 characters. You can assign another
length using SDIM, but you must do so before your program refers to the
string. If your program contains an SDIM that sets the length of a string that
your program has already referenced, then BASIC prints a REDIMENSION
error message.
You can change the default length of string variables by using the second form
of SDIM shown above. For example, to change the default string length to 20,
your program should include the statement “SDIM = 20.” This statement does
not change the lengths of any strings that your program already defined.
SDIM sets up the length only of a scalar (non-array) string; to establish the
length of a string array, you must use the DIM statement.
You can use SDIM to set up more than one variable at a time; see line 10 below
for an example.
>RUN
Christmas time is for children, and adults too.
READY – RAM 1
>
Commands and Statements 10-105
The following program example produces an error at line 120 because it tries to change the
length of string variable A$ after your program has already created the string.
10 PRINT A$
.
.
120 SDIM A$(30)
>RUN
ERROR: REDIMENSION - IN LINE 120
SGN
Returns the sign.
SGN(expr)
Discussion SGN returns a 1 if the argument is positive; a 0 if the argument is zero; and a
-1 if the argument is negative.
>RUN
0 -1 1
READY – RAM 1
>
10-106 Series 30/40 BASIC Guide
SIN
Returns the sine.
SIN(expr)
Discussion Like all numeric functions, SIN may appear on the right of an assignment
statement, within a PRINT statement, and as part of an arithmetical
expression. The argument for the SIN function is a value expressed in radians;
divide degrees by 57.29577 to convert degrees to radians.
Trigonometric The sine of a triangle is the length of the opposite side divided by the length of
Relationships the hypotenuse side (a/c). See the figure below for the relationships between
SIN Ø, side a, and side c.
+1
c
a SINE 0
Ø
-1
0 90 180 270 360
SIN Ø = a/c a =SIN Ø c c = a/SIN Ø
ANGLE (degrees)
>RUN
Enter angle in degrees 30
Enter length of side a 70
Length of side c is 140
READY – RAM 1
>
Commands and Statements 10-107
SPC
Prints spaces in a PRINT statement.
SPC(iexpr)
Discussion SPC prints the number of spaces specified in iexpr in a PRINT statement.
>RUN
over there
insure vehicles
READY – RAM 1
>
SQR
Returns the square root.
SQR(expr)
>RUN
1 1
5 2.236068
9 3
13 3.6055513
17 4.1231057
21 4.5825757
READY – RAM 1
>
10-108 Series 30/40 BASIC Guide
ST@
Stores one or more variables in memory.
Where iexpr is the starting memory location to hold variable var1 and optional variables var2
through varx.
Discussion The ST@ statement stores one or more variables starting at a specified location
within memory. This is useful when your program must save numbers and/or
strings in either memory for later retrieval.
There is a special variable called VAD that holds the last address plus 1 used
by your most recent ST@ (or LD@) command. This is especially useful when
storing strings, because it helps you eliminate the bookkeeping that is otherwise
necessary to keep track of the next available location.
See the description of LD@ earlier in this chapter for a complete example of using ST@.
Commands and Statements 10-109
STOP
Terminates program execution.
STOP
>RUN
1 1
5 2.236068
9 3
13 3.6055513
17 4.1231057
21 4.5825757
STOP - IN LINE 40
READY - RAM 1
>CONT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20
READY – RAM 1
>
10-110 Series 30/40 BASIC Guide
STR$
Returns the string form of a number.
STR$(expr)
Discussion The STR$ function is the inverse of the VAL function; it turns a number into a
string. This is handy when you want to print a number without printing any
leading spaces.
STR$ converts expr to a string according to the current PRINT USING format,
except that it omits leading spaces.
>RUN
Enter number 12.578
12.578
12.578
012.57
READY – RAM 1
>
Commands and Statements 10-111
TAB
Moves the cursor to the position specified.
TAB(iexpr)
Discussion Within a PRINT statement, TAB tells BASIC to send enough spaces to move
the cursor to the column specified.
>RUN
over there
insure vehicles
READY – RAM 1
>
Compare the printed result of this example to the example shown in the SPC description.
10-112 Series 30/40 BASIC Guide
TAN
Returns the tangent.
TAN(expr)
Trigonometric The tangent of a triangle is the length of the opposite side divided by the length
Relationships of the adjacent side (a/b). See the figure below for the relationships between
TAN Ø, side a, and side b.
8
+10
a TAN 0
TAN Ø = a/b
a = TAN Ø b -10
Ø b = a/TAN Ø
8
>RUN
Enter angle in degrees 73
Enter length of side a 536
Length of side b is 163.87
READY – RAM 1
>
Commands and Statements 10-113
TIME
Returns or sets the built-in TIME variable.
TIME
Discussion BASIC has a special variable called TIME that increases every 5 milliseconds.
When TIME reaches the value of 65,535.995 seconds, it rolls over to 0 instead
of going to 65,536.
The CLOCK 1 command resets TIME to 0, and if BASIC has already executed
an ON TIME command, then CLOCK 1 also enables the ON TIME interrupt.
(CLOCK 0 has no effect on the TIME variable; it simply disables the ON
TIME interrupt.)
Your program can also set the value of TIME by simply equating it to a
numeric value.
Examples The example below shows how your program can set the TIME variable but
that it continually increases:
43.5 43.51
>
10-114 Series 30/40 BASIC Guide
TIME$
Returns or sets the time of day.
Discussion On power-up, the Workstation sets TIME$ to “00:00:00.” Your program can
set TIME$ as shown in the box above. The Workstation considers missing
parameters to be zero; for example, if TIME$ is “11:25:30/40”, the statement
TIME$ = “12” sets the time to 12:00:00.
READY – RAM 1
>
>TIME$ = "15:34:22"
READY – RAM 1
>LIST
10 L$ = LEFT$(TIME$,2)
20 M$ = MID$(TIME$,4,2)
30 R$ = RIGHT$(TIME$,2)
40 PRINT "The time is ";L$;" hours, "; M$; " minutes "
READY - RAM 1
>RUN
The time is 15 hours, 34 minutes
READY – RAM 1
>
Commands and Statements 10-115
TROFF
Turns off tracing of program execution.
TROFF
Discussion TROFF turns off the tracing of program execution; consult the description of
TRON for more information.
Examples 10 FOR I 1 TO 5
20 IF I = 3 THEN GOSUB 100
30 PRINT I
40 NEXT
50 END
100 PRINT "This is GOSUB"
110 RETURN
>TRON
>RUN
[10] [20] [30] 1
[40] [20] [30] 2
[40] [20] [100] This is GOSUB
[110] [30] 3
[40] [20] [30] 4
[40] [20] [30] 5
[40] [50]
READY – RAM 1
>TROFF
>RUN
1
2
This is GOSUB
3
4
5
READY – RAM 1
>
10-116 Series 30/40 BASIC Guide
TRON
Enables tracing of program execution.
TRON
Discussion TRON tells BASIC to print to the console the line number (enclosed within
brackets) of each statement it executes. The TROFF command turns off the
trace mode.
Examples 10 FOR I 1 TO 5
20 IF I = 3 THEN GOSUB 100
30 PRINT I
40 NEXT
50 END
100 PRINT "This is GOSUB"
110 RETURN
>TRON
>RUN
[10] [20] [30] 1
[40] [20] [30] 2
[40] [20] [100] This is GOSUB
[110] [30] 3
[40] [20] [30] 4
[40] [20] [30] 5
[40] [50]
READY – RAM 1
>
VAD
Returns last address plus 1 used by the most recent ST@ or
LD@
VAD
Discussion VAD returns the last address plus 1 used by the most recent ST@ or LD@
command.
VAL
Converts a string to a number.
VAL(sexpr)
VAL can return the value of strings in hexadecimal format, but you should
remember that a hex number ends with the letter H. If you want to convert a
hexadecimal string that does not contain the H, you can use HVAL instead.
>RUN
Enter area ZIP Code 52748
The city is Eldridge, IA
READY – RAM 1
>
10-118 Series 30/40 BASIC Guide
VARPTR
Returns the memory address of a variable.
VARPTR(var)
Discussion VARPTR returns the starting address in external memory of a variable. Your
program can access external memory with the XBY() operator.
The storage format for various variable types is shown below:
The storage of the string itself begins with a length byte that is the actual length of the string
(not the maximum length allowed). The bytes following are the ASCII characters for the
string.
To find out the address of an array variable, var must refer to an element in the array. For
example, VARPTR(A(1)) returns the address of the second element in the floating point array
named A.
Commands and Statements 10-119
Note that VARPTR operates differently for strings. It returns the same value regardless of the
array element:
Examples >A = 10
>PRINT VARPTR(A)
63479
>
VERSION
Returns the version number of the BASIC firmware.
VERSION
Discussion VERSION returns the version number of the BASIC firmware in the
Workstation
.
Examples >PRINT VERSION
5.50
>
10-120 Series 30/40 BASIC Guide
XBY
Retrieves or assigns a value to external memory.
XBY(iexpr)
Where iexpr returns a number between 0 and 65,535; if iexpr is less than 32,768 (8000h), then
XBY refers to external data memory (RAM); otherwise, XBY refers to external code memory
(Flash EPROM).
Discussion XBY retrieves from or assigns a byte value to the external data memory at
address iexpr. If your program refers to addresses at or above 32,768 (8000h),
then XBY refers to code memory, which is Flash EPROM.
You must be careful not to use XBY to change code memory without careful study. Some of
BASIC itself exists in the firmware space above 8000h, and BASIC stores your program at
0A000h in the same area. Please see the discussion of LD@ earlier in this chapter for more
details.
>
Chapter 11
Operators
Series 30/40 BASIC contains a complete set of arithmetic and relational operators. The
generalized form of all arithmetic operators is as follows:
expr op expr
where op is one of the arithmetic operators
Precedence BASIC scans an expression from left to right, performing operations of higher
precedence first and equal precedence from left to right. The order of
precedence for solving mathematical expressions is as follows:
Examples 10 A = 4 + 3 * 2
20 PRINT A
>RUN
10
10 A = 2 * (17 + 4^3)
20 PRINT A
>RUN
162
In the example above, BASIC first performs exponentiation (43), adds that result to 17, and
multiples that result by 2.
11-2 Series 30/40 BASIC Guide
+ (addition)
Returns the sum of numbers or joins strings.
expr1 + expr2
Where expr1 and expr2 are any expressions. If both are strings, then BASIC joins string2 to
the end of string1 and returns that combination as a single string.
Examples >PRINT 3 + 5
8
>
>RUN
Enter first number 12
Enter second number 14
The answer is 26
READY – RAM 1
>
Operators 11-3
– (subtraction or negation)
Returns the difference.
expr1 – expr2
or
– expr3
Examples >PRINT 10 - 25
-15
>PRINT - MTOP
-8192
>RUN
Enter first number 22
Enter second number 14
The answer is 8
READY – RAM 1
>
11-4 Series 30/40 BASIC Guide
* (multiplication)
Returns the arithmetic product of two expressions.
expr1 * expr2
Examples >PRINT 3 * 5
15
>RUN
Enter first number 12
Enter second number 14
READY – RAM 1
>
Operators 11-5
/ (division)
Returns the arithmetic quotient of two expressions.
expr1 / expr2
Where expr1 and expr2 are any numeric expressions. If expr2 is zero, then BASIC issues a
DIVIDE BY ZERO error (error code 10).
>RUN
Enter first number 22
Enter second number 14
READY – RAM 1
>
11-6 Series 30/40 BASIC Guide
^ (exponentiation)
Returns the arithmetic result of a number raised to an
exponent.
expr ^ iexpr
Where expr is any numeric expression; iexpr is an integer between 0 and 255.
Examples >PRINT 6 ^ 4
1296
>RUN
Enter first number 22
Enter exponent 5
READY – RAM 1
>
Operators 11-7
= (equal)
Compares two expressions and returns “true”if they are equal.
expr1 = expr2
Where expr1 and expr2 are either both numeric expressions or both string expressions.
Discussion Relational expressions involve the operators = (equal), <> (not equal), >
(greater than), >= (greater than or equal), < (less than), and <= (less than or
equal). These operators compare two numeric or string expressions and return
a result of “true” or “false.” Numerically, a true result is 65,535 and a false
result is 0.
The relational operators can work with either numeric expressions or string expressions. If a
relational expression contains an argument of each type, BASIC issues a TYPE MISMATCH
error.
BASIC considers strings to be equal or if they are exactly identical. BASIC compares strings
by taking one character at a time from each string and comparing their ASCII codes. If the
ASCII codes are different, then BASIC considers the lower to be less than the higher. If
BASIC reaches the end of one string without differences, then it considers the shorter string to
be less than the longer one. All characters and spaces count; BASIC does not ignore leading or
trailing spaces.
Examples >PRINT 6 = 4
0
>RUN
Enter first number 22
Enter second number 22
Numbers are equal
READY – RAM 1
>
11-8 Series 30/40 BASIC Guide
>RUN
Enter first string: ABC
Enter second string: ABC
Strings are identical
READY – RAM 1
>
Where expr1 and expr2 are either both numeric expressions or both string expressions.
Discussion For a complete description of relational operators, see the Discussion on page
12-7.
>RUN
Enter first number 22
Enter second number 102
READY – RAM 1
>
Where expr1 and expr2 are either both numeric expressions or both string expressions.
Discussion For a complete description of relational operators, see the Discussion on page
12-7.
>PRINT 6 < 4
0
You can use the NOT statement in combination with relational operators to invert a result, as
shown in the examples below:
11-10 Series 30/40 BASIC Guide
>RUN
Enter first number 22
Enter second number 22
READY – RAM 1
>
Where expr1 and expr2 are either both numeric expressions or both string expressions.
Discussion For a complete description of relational operators, see the Discussion on page
12-7.
>PRINT 6 > 4
65535
You can use the NOT statement in combination with relational operators to invert a result, as
shown in the examples below:
Operators 11-11
>RUN
Enter first number 45
Enter second number 22
Result is true
READY – RAM 1
>
Where expr1 and expr2 are either both numeric expressions or both string expressions.
Discussion For a complete description of relational operators, see the Discussion on page
12-7.
>PRINT 6 <= 4
0
You can use the NOT statement in combination with relational operators to invert a result, as
shown in the examples below:
11-12 Series 30/40 BASIC Guide
>RUN
Enter first number 45
Enter second number 22
READY – RAM 1
>
Where expr1 and expr2 are either both numeric expressions or both string expressions.
>PRINT 6 >= 4
65535
You can use the NOT statement in combination with relational operators to invert a result, as
shown in the examples below:
Operators 11-13
>RUN
Enter first number 45
Enter second number 22
Result is true
READY – RAM 1
>
Chapter 12
Logic
BASIC provides the logic functions associated with industrial control applications. In all,
seven logic functions are available; these are:
Truth Tables The results of logic functions to their inputs are summarized in the truth table
below. For the following, the function is assumed to contain two inputs,
however the truth table is identical for any number of inputs to the function.
AND
Returns the logical AND.
Where iexpr1 and iexpr2 are any positive integer expressions. Although control logic results
are 0 or 1, the AND operator does a “bitwise” AND on each bit of the integers. For example:
A B A
][ ][ C C
B
Truth Table
C = A AND B
A B C
0 0 0
0 1 0
1 0 0
1 1 1
Examples >PRINT 3 AND 2
2
OR
Returns the logical OR of two expressions.
iexpr1 OR iexpr2
Where iexpr1 and iexpr2 are any positive integer expressions. Although control logic results
are 0 or 1, the OR operator does a “bitwise” OR on each bit of the integers. For example:
A
][ C A
C
B
][ B
Truth Table
C = A OR B
A B C
0 0 0
0 1 1
1 0 1
1 1 1
Examples >PRINT 4 OR 1
5
>PRINT 1 OR 0 OR 1 OR 0
1
12-4 Series 30/40 BASIC Guide
XOR
Returns the logical exclusive-OR.
Where iexpr1 and iexpr2 are any positive integer expressions. Although control logic results
are 0 or 1, the XOR operator does a “bitwise” XOR on each bit of the integers. For example:
A
][ X
B A
][ C
B
A X
][ ][ C
B
][
Truth Table
C = A XOR B
A B C
0 0 0
0 1 1
1 0 1
1 1 0
INV
Returns 0 if the expression <> 0; returns 1 if the expression =
0.
INV(iexpr)
Where iexpr is any positive integer; if iexpr is not 0, then the INV operator returns 0; if [expr]
is 0, then INV returns 1.
A
][ B A A
B
][ C C=A
Truth Table
B = INV(A)
A B
0 1
1 0
INV AND
Returns the logical NAND.
Where iexpr1 and iexpr2 are any positive integer expressions. INV returns 0 if the result of
the AND is non-zero, and returns 1 if the result is 0.
A
A
][ C
C
B B
][
Truth Table
C = INV(A AND B)
A B C
0 0 1
0 1 1
1 0 1
1 1 0
>RUN
?0
?1
1
READY – RAM 1
>
Logic 12-7
INV OR
Returns the logical NOR.
INV(iexpr1 OR iexpr2)
Where iexpr1 and iexpr2 are any positive integer expressions. The previous numeric
examples don’t really apply, since INV returns 0 if the result of the OR is non-zero, and INV
returns 1 if the result of is 0.
A B A
][ ][ C C
B
Truth Table
C = INV(A OR B)
A B C
0 0 1
0 1 0
1 0 0
1 1 0
>RUN
?0
?1
0
READY – RAM 1
>
12-8 Series 30/40 BASIC Guide
INV XOR
Returns the logical XNOR.
Where iexpr1 and iexpr2 are any positive integer expressions. The previous numeric
examples don’t really apply, since INV returns 0 if the result of the XOR is non-zero, and INV
returns 1 if the result of is 0.
A B
][ ][ X A
C
A B B
][ ][ C
X
][
Truth Table
C = INV(A XOR B)
A B C
0 0 1
0 1 0
1 0 0
1 1 1
>RUN
?17
?17
1
READY – RAM 1
>
Chapter 13
CALLs
To make specific features of the Workstation easier to use, we’ve included some built-in
subroutines that you can access through a CALL statement. If the number following the CALL
is between 1 and 127, then the CALL refers to a built-in subroutine, not to a machine language
subroutine you may have placed in memory yourself.
When a CALL requires that you provide data, your program must first PUSH the data on the
stack; other CALLs return a result that you must POP after the CALL. The rest of this chapter
describes each CALL and indicates when it requires input data or returns output data.
If the CALL does not require input or return a result, you need only the CALL alone, as shown
in the format below, where iexpr is the number of the CALL.
CALL iexpr
If the CALL requires input, you must PUSH the data on the stack first, as shown in the
following format, where expr must return a numeric result:
If the CALL returns a result, you must POP the result into a numeric variable after the CALL,
as shown in the following format:
CALL 12
Clears to the end of the display.
CALL 12
Discussion CALL 12 erases the display from the current cursor position to the bottom
right corner of the screen.
CALL 13
Clears to the end of the line on the display.
CALL 13
Discussion CALL 13 erases the display from the current cursor position to the end of the
current line.
CALL 30
Turn on COM1’s RTS line.
CALL 30/40
Discussion CALL 30 turns on the RTS line on COM1. In order for this to work properly,
you must open COM1 with the RN parameter. CALL 33 turns off RTS.
CALL 33
Turn off COM1’s RTS line.
CALL 33
Discussion CALL 33 turns off the RTS line on COM1. In order for this to work properly,
you must open COM1 with the RN parameter. CALL 30 turns on RTS.
CALL 38
Enters the on-line configuration menu.
CALL 38
Discussion CALL 38 enters the on-line configuration menu, which allows you to
configure many of the Workstation’s operating parameters.
When you exit from the on-line configuration menu, the Workstation “warmstarts” BASIC,
which means that it clears all variables. Although a running program can contain CALL 38,
exiting from the on-line configuration menu cannot return you to the program.
However, if you set up your Workstation with REACT R, then the unit automatically runs the
program after returning from the on-line configuration menu.
CALL 39
Enters the monitor.
CALL 39
Discussion CALL 39 enters the Workstation’s internal “monitor” program. When you
enter the monitor, you see the following screen:
Debug Monitor(V2.00)
Ready>
When the monitor is running, you can download new firmware. You can
also type some special commands, including INIT, which performs a first-
time initialization of BASIC and erases the current program from memory.
The other monitor commands are not useful.
CALLs 13-5
CALL 40 and 41
Returns the number of characters in COM1 buffer.
Discussion These CALLs return the number of characters in a port’s receive or transmit
communications buffer. For example, if the result of CALL 40 is 2, that means
that there are two characters waiting in port #1’s receive buffer; your program
can fetch these characters with an INPUT or INPUT$ statement.
As another example, if the result of CALL 41 is 15, that means that there are 15 characters in
port #1’s transmit buffer remaining to be sent; your program can watch this value to make sure
characters are going out; if the value doesn’t change, then transmitting has halted for some
reason.
CALL Function
40 Port #1 receive
41 Port #1 transmit
CALL 82
Prints a list of all variables used.
CALL 82
Discussion CALL 82 prints a list of all the variables created by your program. You
must execute this CALL after you run your program. The list is in the
sequence in which the variables are first used by your program. For each
item in the list that is an array, string, or string array, the list includes the
number of elements in the array and/or the maximum length of the string.
>CALL 82
A$(127)
B$(27)
K$(27,20)
K(27)
I
I%
I%(10)
M
MH
X
P
ER
Appendix A
Speed-up Hints
This section offers some programming techniques you can use to squeeze the maximum speed
out of your BASIC program.
Subroutines Whenever BASIC executes an instruction that goes to a line number (GOTO,
GOSUB, ON ERROR and ON TIME), it starts looking for that line number
from the beginning of the program.
If you have subroutines that your program calls frequently, then you should
place them as close as possible to the beginning of your program. For example,
many experienced programmers start their programs with the instruction
“GOTO 1000” and use line numbers 10 through 999 for subroutines.
Variables Each time your program creates a variable, BASIC assigns it to the next position
in the list. And every time your program refers to a variable, BASIC looks
through the list starting with the first variable created.
To gain maximum speed in the use of variables, your program should create the
most-used variables first. For example, if your program frequently refers to X
and Y, then your program could simply contain the following line to create
those variables: Y = 0 : X = 0. Because you listed Y first, BASIC finds it first.
BASIC uses 12 microseconds to scan through each variable when it searches for
a variable.
A-2 Series 30/40 BASIC Guide
Constants When BASIC encounters a constant, such as 7 or 3.2728, it must convert that
number into its internal format. Because this takes more time than simply
looking up a variable, you should convert frequently-used constants to variables
instead.
For example, you might want to initialize an array of 100 numbers to the value
55. Although each of the following routines accomplishes this, the second
routine is 25 milliseconds faster than the first:
Integer vs. BASIC performs 4-function arithmetic about twice as fast when using integer
Floating Point variables (indicated with the % symbol) instead of floating point.
For floating-point operations such as trigonometric functions, your program runs
faster if you use floating-point variables. When you use integer variables in
floating-point operations, BASIC converts the integer to floating point before
processing.
FOR . . . NEXT The best way to speed up a FOR-NEXT loop is to omit the optional variable
Loops following NEXT. For example, although the following two lines are equivalent,
the second executes about 10% faster than the first:
BASIC Differences
Hardware- Because the Series 30/40 Workstation is fundamentally different from the IBM
specific PC, it lacks GW-BASIC’s graphics, sound, disk-handling, microprocessor-
specific functions, DOS-specific functions, and some keyboard capabilities.
functions
Because the Workstation’s microprocessor has four distinct memory types
instead of the IBM PC’s single type of memory, Series 30/40 BASIC uses XBY,
DBY, CBY, and IBY commands instead of GW-BASIC’s PEEK and POKE
commands.
Variable labels, Because the Workstation supports a much smaller memory, its labels have only
arrays, two significant characters while GW-BASIC supports up to 40. Also, Series
30/40 BASIC supports only single-dimension arrays, while GW-BASIC
functions supports up to 255 dimensions. Finally, Series 30/40 BASIC does not support
the function (FN) capability of GW-BASIC.
Strings Series 30/40 BASIC requires you to specify the maximum length of a string (up
to 254 characters) before you use it; otherwise, its default maximum length is
10. In GW-BASIC, all strings may vary in size up to 255 characters, but when
the string space is full, GW-BASIC pauses to perform “garbage collection.”
Thanks to the Workstation’s pre-defined string lengths, it never has to take time
to collect garbage.
Numbers The numeric variable types available in Series 30/40 BASIC are fewer in
number and different from GW-BASIC’s number types. The Workstation’s
floating point numbers have 8 digits of precision and a range of 10-99 to 1099,
while GW-BASIC’s floating point numbers have 7 digits (single-precision) or
17 digits (double-precision) of precision and a range of 10-38 to 1038. Series
30/40 BASIC supports 17-bit integers that range from -65,535 to +65,535, while
GW-BASIC’s integers are only 16 bits that range from -32,767 to +32,767.
PRINT USING The Workstation’s USING statement offers only a subset of the capabilities of
GW-BASIC’s USING statement. However, because virtually all of the
unsupported features are handy only for accounting-oriented systems, you
probably won’t feel the loss.
Other Series 30/40 BASIC does not support octal representation of numbers, but its
differences support for hexadecimal numbers significantly exceeds that of GW-BASIC.
Series 30/40 BASIC’s implementation of the OPEN command is significantly
different, and its storage format for variables means that the VARPTR function
yields significantly different results.
Appendix C
Memory Map
This section shows how BASIC uses the Workstation’s memory. At the end of this section is
an illustration of BASIC’s use of the microprocessor’s memory. In order to understand fully
how this memory map works, you should be familiar with the internal and external memory
capabilities of the 8032 microprocessor and have data sheets for the microprocessor and Optrex
DMC20261NY-LY-NM LCD display.
Note This memory map is provided for your reference only and
is not guaranteed to remain consistent with future firmware
revisions.
INDIRECT RAM
FFh
MEMORY-MAPPED I/O
8000h (Display = 8000h) Flash EPROM
SPECIAL FUNCTION 7FFFh (2000h to FFFFh)
REGISTERS Free space (if MTOP is set
lower than its default value)
VARTOP (Downloadable
80h
(= MTOP) Scalar variables firmware)
VARUSE
Free space
DIMUSE
80h Arrays and strings
7Fh
EXTERNAL RAM
(0 to 7FFFh)
INTERNAL RAM
User program (when editing)
1000h 2000h
(BASIC and BIOS FFFh 1FFFh
INPUT buffer
scratch pad) F00h
EFFh Microprocessor ROM
E00h String operation buffer
DFFh (Firmware)
BASIC and BIOS memory
0 0 0
Accessed by Accessed by XBY(x) Accessed by CBY(x)
Series 30/40 BASIC Guide
Reference
Command Summary
Command Description Examples
ABS(expr) Returns the absolute value. X = ABS(–5) + ABS(6*(–5))
MID$(svar,iexpr1{,iexpr2}) Places a string within svar starting at position A$ = “IPT” : MID$(A$,2) =“WS”
iexpr1 and continuing for a length of iexpr2. REM A$ = “IWS”
MTOP Returns or sets the top of memory. MTOP = 7138 : PRINT MTOP
NEW Deletes program and clears all variables. NEW
NOT(expr) Returns 16-bit 1’s complement. X = NOT(23) : REM X = 65512
ON ERROR GOTO line# Enables error handling routine. ON ERROR GOTO 700
ON ex GOSUB line#, line# Selects subroutine number ex and calls it. ON A GOSUB 100, 200, 300
(gosub 100 if A = 0, 200 if A = 1, etc.)
ON expr GOTO line#, line# Selects line number expr and goes to it. ON A GOTO 100, 200, 300
(goto 100 if A = 0, 200 if A = 1, etc.)
ON TIME=ex GOSUB line# Sets up time-based interrupt handler to call ON TIME = 5 GOSUB 100
the subroutine at line# when TIME ≥ ex.
D-4 Series 30/40 BASIC Guide
PRINT USING sexpr Sets up format of printed numbers. PRINT USING “##” : PRINT USING I$
RAM prog Selects program prog as the current program. RAM 1 : RAM 2
RAM prog1 = RAM prog2 Inserts a copy of program prog2 before RAM 2 = RAM 5
prog1.
REACT {par} {,par} Specifies start-up action after reset. REACT B : REACT R, M, N
none = deselects all options. REACT RAM 1
R = run program 1 after reset.
P = protect program by locking it in run mode.
Cx = set console to port x
READ var {,var} Reads DATA value and assigns to var. READ A, B : READ A(I)
RENUM {new}{,inc}{,start} Renumbers the lines from start to end; the new RENUM : RENUM 10,100
{,end} first line number is new and subsequent line RENUM 1000,10,120,290
numbers are incremented by inc.
ROM = RAM prog2 Copies RAM program to permanent memory ROM = RAM 1
in Flash EPROM.
RUN {line#}{RAM prog} Executes current program or program prog RUN : RUN 110 : RUN RAM 1
at first line or line#. RUN 110 RAM 1
SDIM svar(len) Sets the maximum length of a string variable. SDIM A$(45) : SDIM C$(30/40),B$(20)
Operators
Operator Description Examples
expr <> expr Compares two expressions for non–equality. X = 4 <> 4 REM X = 0
expr1 < expr2 Compares expr1 for less than expr2. X = 3 < 4 : REM X = 65535
expr1 > expr2 Compares expr1 for greater than expr2. X = 3 > 4 : REM X = 0
expr1 <= expr2 Compares expr1 for less than or equal to expr2. X = 3 <= 4 : REM X = 65535
expr1 >= expr2 Compares expr1 for greater than or equal to expr2. X = 4 >= 4 : REM X = 65535
Reference D-7
CALLs
CALL Description Examples
CALL 12 Clears from cursor position to end of display. CALL 12
CALL 13 Clears from cursor position to end of line on display. CALL 13
CALL 30 Turn off the RTS line of COM1. CALL 30
CALL 33 Turn on the RTS line of COM1. CALL 33
CALL 38 Runs on-line configuration program. CALL 38
CALL 39 Runs monitor. CALL 39
CALL 40 Returns number of characters in port #1 receive buffer. CALL 40 : POP var
CALL 41 Returns number of characters in port #1 transmit buffer. CALL 41 : POP var
CALL 82 Prints a list of the variables used. CALL 82
Ports
When communicating, the display and keyboard are also considered to be a port. The
following table summarizes the port names and numbers:
Error Codes
The following table shows the Workstation’s error codes. If you write an “ON ERROR”
routine, your routine must check the error code returned (ERR) as well as the line number
where the error occurred (ERL) in order to handle the error.
At the end of the table are “non-recoverable” errors; if one of these errors occurs, the
Workstation does not go to your error handler and instead simply stops program execution and
prints the error message.
40 BAD ARGUMENT Illegal address for DBY; invalid parameter or parameter format in OPEN or
REACT statement; invalid argument for TIME$ or DATE$; invalid parameter
for CHR$, LEFT$, RIGHT$, MID$, INPUT$ or INSTR$ statement (i.e.,
integer exceeds 255); bit number outside the range 1 to 16 in BIT statement;
bad argument in LOCATE statement; parameter greater than 255 in many
other statements.
50 TYPE MISMATCH Function that expects a string gets a number instead; a function that expects a
number gets a string instead; or a function that expects an integer gets a
floating point number instead.
E-2 Series 30/40 BASIC Guide
60 STRING TOO LONG String expression exceeds the maximum length assigned to the variable, or a
string operation resulted in an overflow of the string buffer. If the former, a
program can “truncate” the string; if the latter, you can break up a single
expression into several multiple expressions where each yields an intermediate
result.
70 * KEYBOARD BUFFER Operator pressed enough keys to fill up the keyboard buffer. This message
OVERFLOW occurs only when COM0 is opened with the IB parameter, and usually
indicates that the program fails to read the keyboard frequently enough.
72 KEYBOARD INPUT Operator failed to press a key in response to an INPUT or INPUT$ statement
TIMEOUT within the time period specified by the TD parameter in the OPEN statement
for COM0. This can be a useful error to generate so as not to leave a program
suspended while waiting for operator input.
75 I/O RACKS DISABLED; Program contains a SCAN command; this command is not supported on the
CAN'T SCAN Series 30/40 Workstations.
80 * COM1 RX OVERFLOW Workstation received a character when the 255-character buffer was already
full; to avoid this error, try implementing XON/XOFF or RTS handshaking
(use the RX or RH parameter in the OPEN command).
81 * COM1 TX TIMEOUT CTS input did not come active or XON was not received within the time
period specified by the CS or TX parameter; this occurs when the other device
is not connected properly, not operating properly, or the program doesn't wait
long enough for the other device to come ready.
83 * COM1 PARITY Parity error occurred during the reception of a character; this can happen
because of electrical noise or improper communication parameter settings.
85 COM1 INPUT TIMEOUT Workstation did not receive a character in response to an INPUT or INPUT$
statement within the time period specified by the TD parameter in the OPEN
statement for COM1. This can be a useful error to generate so as not to leave a
program suspended while waiting for input.
87 COM1 TRANSMIT User program attempted to print to COM1 when the buffer is full. This can
OVERFLOW occur subsequent to COM1 TRANSMIT HANDSHAKE TIMEOUT if the CTS
input is not asserted.
ARRAY SIZE In DIM statement, array size exceeds 254, string length exceeds 254, or
memory required exceeds memory available; otherwise, element number
exceeds number of elements in array.
A-STACK Too many levels of parentheses in an expression or PUSHes don’t match POPs
or CALLs that push and pop; if the former, break up the expression into
smaller expressions that yield intermediate results.
BAD PROGRAM Program is scrambled and will not run; indicates possible problem with
CHECKSUM electrical noise scrambling the memory.
Error Codes E-3
BAD SYNTAX Invalid command or statement, or variable name includes a reserved word.
CAN’T CONTINUE CONT won’t work if a program terminated normally or with an error; CONT
works only if a program terminates with a [Ctrl]-C.
CAN’T RESUME RESUME won’t work unless it’s at the end of an error-handling routine.
C-STACK Mismatch between variable following NEXT and the variable following the
corresponding FOR; UNTIL, WHILE, NEXT, RETURN or RETI without
corresponding control statement; too many levels of nesting; or end of program
found at end of DO or FOR statement. Also, use the CLEAR command from
within a subroutine clears all stacks, so the RETURN statement at the end of
the subroutine will cause a C-STACK error.
EXTRA IGNORED INPUT received either string input that exceeded the maximum string length
or received more numbers than INPUT expected.
I-STACK Expression is too complex for BASIC to handle. Almost invariably indicates
that an expression contains too many levels of parentheses. The solution is to
re-write the expression to eliminate nesting, re-write it so that higher-
precedence operators come first, or break it up into two or three expressions
that return intermediate values.
ILLEGAL DEFERRED Attempt to execute a command in the Run mode that executes only in the
Command mode, such as CONT.
ILLEGAL DIRECT Attempt to execute a command in the Command mode that executes only in
the Run mode, such as STOP or RESUME.
NO DATA Attempt to READ found no data, either because the program contains no
DATA statements or because previous READs have already exhausted all the
DATA statements. This can occur if you re-start a program with a GOTO
instead of RUN, so if you want to do that, put a RESTORE before the first
READ.
NO SUCH PROGRAM Reference to a program that doesn’t exist; for example, RAM1 = RAM 2 when
RAM 2 doesn’t exist or DEL RAM 3 when RAM 3 doesn’t exist.
REDIMENSION Program contains a DIM or SDIM for an array variable that already exists
either because of a previous DIM or because of a previous use that created the
array by default. This can occur when re-starting a program with a GOTO
instead of a RUN, but there is no remedy except to avoid executing the extra
DIM or SDIM statements.
ROM WRITE Attempt to write to a location in Flash EPROM that is already written.
OUT OF MEMORY Program has grown too large during editing or renumbering or the program
has created too many variables during execution.
UNDEFINED LINE GOTO, GOSUB, ON ... GOTO, ON ... GOSUB, ON TIME, or ON ERROR
NUMBER refers to a line number that doesn't exist in the program.
* Indicates an asynchronous error that can occur at any time during program execution, without regard to the statement
BASIC is current executing. When an asynchronous error occurs, the error number (ERR) is valid but the error line
number (ERL) is irrelevant.