Sample Program:

This procedure uses MOD to execute repeatedly a sequence of GOSUB commands. A loop of index of 80 causes execution to jump to each line number in the list 10 times.

PROCEDURE repeat
OSHELL "TMODE -PAUSE"
ODIM T: INTEGER
OFOR T=1 TO 80
DON MODCT,8)+1 GOSUB 10,20,30,40,50,60,70,80
ONEXT T
OSHELL "TMODE PAUSE"
REND
1 00PR I NT USING "S1 0"" , "*" \ RETURN
200PRINT USING "S10^","**" \ RETURN
300PRINT USING "S10^.1711***" \ RETURN
400PRINT USING "S10^","****" \ RETURN
500PRINT USING "S10^.1711*****" \ RETURN
600PRINT USING "S10^","****" \ RETURN
70EPRINT USING "S10^","***" \ RETURN
80EPRINT USING "S1 0^" , "* *" \ RETURN
DE ND

11-iol
BASIC09 Reference

ON/GOTO Jump to line number on a


Syntax: ON pos GOTO linenum [,linenum,...]

Function: Transfers procedure control to the line number located at position pos in the list of line numbers immediately following the GOTO command. For example, if pos equals 1, BASIC09 branches to the first line number it encounters in the list. If pos equals 2, BASIC09 branches to the second line number it encounters in the list. If pos is greater than the number of items in the list, execution continues with the next command line. To use ON/GOTO you must have numbered lines to match the line numbers in the list.


Parameters:

pos An integer value in a range from 1 to the
number of items in the list following GOTO.
linenum Any numbered line in the procedure.

Examples:

PRINT "You can now: C1) End the program C2) Print
the re5ult5"
PRINT " C3) Try again C4) Start
a new program"
INPUT "Type the letter of your choice: ",choice
ON CHOICE GOTO 100, 200, 300, 400

Sample Program:

This procedure converts decimal numbers to binary. It uses ON GOTO to execute the operation you select from a menu: Convert a number, display the result of all conversions, or end the program.

PROCEDURE bicalc
ODIM^NUMBER,NUM,X,STORAGE:INTEGER;^BI:STRING;
^ARRAYC50,2):STRING
pCOUNT=0

11-102


100HI="" \NUMHER=0 \NUM=0 \X=0 \STORAGE=0 DINPUT "Number to convert to binary ",NUMBER DIF NUMBER=0 THEN END DENDIF ONUM=LOG10CNUMHER)/.3 ONUM=2^NUM \STORAGE=NUMBER OREPEAT OX=NUMBER/NUM DI F X > 0 THEN H I =H I +"1 " ONUMHER=MODCNUMHER,NUM) OELSE HI=HI+"0" DENDIF ONUM=NUM/2 DUNTIL NUM<=1 OIF NUMHER>0 THEN OH I =H 1 +111 " OELSE^HI=HI+"0" REND I F OPRINT STORAGE; " _ "; HI; " in binary." OPRINT OCOUNT=COUNT+1 OARRAYCCOUNT,1)=STR$CSTORAGE) OARRAYCCOUNT,2)=HI 12FIPRINT "Do you want to: C1) Convert another number." O P R I N T "OOOOOOOOOOOOOOOO C 2) D i 5 p 1 a y all c a 1 c u 1 a t i o n 5 thus far." O P R I N T "OOOOOOOOOOOOOOOO C 3) End the program." DINPUT "Enter 1, 2, or 3...",choice DON choice GOTO 10,20,30 REND 200FOR T=1 TO COUNT OPRINT ARRAYCT,1); " _ "; ARRAYCT,2) ONEXT T OGOTO 1 2 300PRINT \ PRINT " Program Terminated" REND

11-103
BASIC09 Reference

OPEN Opens a path to a device



Function: Opens an input/output path to a disk file or to a device. When you open a file, you can select one or more of the following access modes:

Mode Function
READ Lets you read (receive) data from a file or
device but does not allow you to write (send)
data.
WRITE Lets you write data to a file or device but does
not allow you to read data.
UPDATE Lets you both read from and write to a file or
device.
EXEC Specifies that the file you want to access is in
the current execution directory.
DIR Specifies that the file you want to access is a
directory-type file.
Parameters:
path The variable in which BASIC09 stores the
number of the newly opened path.
pathlist The route to the file or device to be opened,
including the filename if appropriate.
access mode The type of access the system is to allow for
the file or device. Use a plus symbol to specify
more than one type of access.

11-104







__ in a file as single bytes or in groups of any size you want.










This procedure opens a path to both the SYS directory on Drive /DO and the error message file.

PROCEDURE readerr ODIM A:STRINGL801 ODIM PATH:HYTE EOPEN #PATH,"/D0/SYS/ERRMSG":READ OWHILE EOFC#PATH)<>TRUE DO DREAD #PATH,A SPRINT A EENDWHILE OCLOSE #PATH REND

11-105
BASIC09 Reference

OR Performs a Boolean OR operation

Syntax: operand l OR operand2

Function: Performs an OR operation on two or more values, returning a Boolean value of either TRUE or FALSE.

Parameters:

operandl Either numeric or string values.
opera

Examples:
PRINT A>3 OR B>3
PRINT A$="YES" or B$="YES"

11-106


Sample Program:

This procedure asks you to type a word or phrase, then converts all lowercase characters to uppercase. It uses OR to test for a character in your word or phrase that is outside of the ASCII values for lowercase letters. If it is, the character does not need converting.

PROCEDURE uppercase ODIM PHRASE,NEWSTRING:STRINGL807; CHARACTER: STRINGL1J; T,X:INTEGER ONEWSTRING="" PHRASE="" OPRINT "Type a phrase in lowercase and I will make it uppercase." OINPUT PHRASE OFOR T=1 TO LENCPHRASE) OCHARACTER=MID$CPHRASE,T,1) OX=ASCCCHARACTER) DIF X<97 OR X>122 THEN ONEWSTRING=NEWSTRING+CHARACTER OELSE OX=X-32 ONEWSTRING=NEWSTRING+CHR$CX) REND I F ONEXT T OPHRASE=NEWSTRING ONEWSTRING="" OPRINT PHRASE REND

11-107
BASIC09 Reference





Function: Defines the parameters that a called procedure expects to receive from the procedure that calls it. When using PARAM, be sure that the total size of each parameter in the calling procedure's RUN statement is the same as the defined size in the called procedure's PARAM statement.


Parameters:
variable A simple variable, an array structure, or a
complex data structure.
type Byte, Integer, Real, Boolean, String, or user
defined.
Notes:






BASIC09 Command Reference l 11

You can declare several variables of the same type by separating them with commas. To separate variables of different types, follow each type group with a colon, the type name, and then a semicolon.


If you do not include a maximum length for a string variable enclosed in brackets following the type, like this:




BASIC09 uses a default length of 32 characters for strings. You can declare shorter or longer lengths, to the capacity of BASIC09's memory.


0 Arrays can have one, two, or three dimensions. The PARAM format for dimensioned arrays is the same as for simple variables except you must follow each array name with a subscript, enclosed in parentheses, to indicate its size. The maximum array size is 32767.


Arrays can be either of the standard BASIC09 type, or of a user-defined type. To create your own data types for simple variables, arrays, and complex data structures, see TYPE.


Examples:

PARAM NUMBER: INTEGER

PARAM NAME:STRINGL25];ADDRESS:STRINGL30J;ZIP: INTEGER

PARAM N01,N02,NO3:REAL;NO4,NO5,NOG:INTEGER;NO7: BYTE

Sample Program:

The first procedure asks you to enter a decimal number. Then, it asks you to choose whether you want to convert the number to binary or hexadecimal. Depending on your choice, the procedure calls (using RUN) either a procedure named Binary or a procedure named Hex. It passes the number you typed to the appropriate procedure for conversion.


11-109
BASIC09 Reference

PROCEDURE convert
ODIM NUMBER,CHOICE:INTEGER
OPRINT USING "S80^"; "Hexadecimal - Binary
Conversion Program"
OPRINT
100INPUT "Number to convert...",NUMBER
OIF NUMBER=0 THEN
REND
OENDIF
DINPUT "Choose: C1) Binary or C2) Hex...",CHOICE
DON CHOICE GOTO 20,30
200RUN BINARYCNUMBER)
OGOTO 1 0
300RUN HEXCNUMBER)
OGOTO 1 0
REND

PROCEDURE binary
ODIM NUM,X,STORAGE:INTEGER; BI :STRING;
ARRAYC50,2):STRING
OPARAM NUMBER: INTEGER
OCOUNT=0
OBI="" \NUM=0 \X=0 \STORAGE=0
ONUM=LOG10CNUMBER)/.3
ONUM=2^NUM \STORAGE=NUMBER
OREPEAT
OX=NUMBER/NUM
OIF X>0 THEN
OBI =BI +"1 "
ONUMBER=MODCNUMBER,NUM)
OELSE
OBI=BI+"0"
DENDIF
ONUM=NUM/2
RUNT I L NUMc =1
OIF NUMBER>0 THEN
OBI=BI+"1"
OELSE
OBI=BI+"0"
DENDIF
OPRINT STORAGE; " _ "; BI; " in binary."
OPRINT
REND

11-110
BASIC09 Command Reference l 11

PROCEDURE hex
pDIM NUM,X,STORAGE:INTEGER; TAHLE,HX:STRING;
ARRAYC50,2):STRING
pPARAM NUMBER:INTEGER
pTAHLE="123456789AHCDEF"
pHX="" \NUM=0 \X=0 \STORAGE=0
pNUM=LOG10CNUMHER)/1.2
pNUM=16^NUM \STORAGE=NUMBER
pREPEAT
pX=NUMBER/NUM
pIF X>0 THEN
pHX=HX+MID$CTAHLE,X,1)
pNUMHER=MODCNUMHER,NUM)
pELSE HX=HX+"0"
pEND I F
pNUM=NUM/ 16
pUNTIL NUM<=1
pIF NUMHER>O THEN
pHX=HX+MID$CTAHLE,NUMHER,1)
pELSE
pHX=HX+"0"
pEND I F

pPRINT STORAGE;
pPRINT
pEND

HX;

" in hexadecimal."
BASIC09 Reference

PAUSE Suspends execution and enters Debug

Syntax: PAUSE text

Function: Suspends the execution of a procedure and causes BASIC09 to enter the DEBUG mode. If you include text with the PAUSE command, it is displayed on the screen.

Place PAUSE statements in a program temporarily to observe the way in which the procedure operates and to track down programming errors. When the procedure is operating correctly, remove the PAUSE statement.

After using DEBUG, you can continue execution of the paused procedure with the CONT command.

Parameters:
text A message you want PAUSE to display on the
screen when BASIC09 executes the statement.
Examples:
PAUSE

PAUSE The array is now full.

11-112
B ASIC09 Command Reference l 11

PEEKReturns the value in a memory location

Syntax: PEEK(mem)

Function: Returns the value of a memory byte as a decimal integer. The value returned is in the range 0 to 255. PEEK is the complement of the POKE statement.

See also ADDR.

Parameters:

mem An integer value representing the location of
the memory byte you want to examine. The
memory byte is relative to the current pro
cess's address space.
Examples:
PRINT PEEKC15250)
MEMVAL = PEEKC4450)

11-113
BASIC09 Reference

Sample Program:

This procedure asks you to type a phrase in uppercase characters. It then uses ADDR to locate the area in memory where BASIC09 stores the phrase. Next, it reads each character from memory with PEEK, converts it to lowercase if necessary, and pokes the new value back into the same location. When the procedure displays the contents of the phrase, it is all lowercase.


PROCEDURE lowercase ODIM LOC,T:INTEGER; PHRASE:STRINGI80J OPRINT "Type a phrase in UPPERCASE and I'll make it lowercase." OINPUT PHRASE OLOC=ADDRCPHRASE) OFOR T=LOC TO LOC+LENCPHRASE) OX=PEEKCT) OIF X>32 AND X<91 THEN OX=X+32 OPOKE T, X REND I F ONEXT T OPRINT PHRASE REND

11-114


PI Returns the value of pi

Syntax: PI

Function: Returns the constant value 3.14159265. Parameters: None Examples:

PRINT "The area of a circle with a radius of 6 inches ir 11;PI*6A

Sample Program:

This procedure uses the formula (PI + 2)/15 as a basis for calculating a screen position. Taking the sine of the formula, it prints a sine wave of asterisks down the screen.

PROCEDURE picalc
ODIM FORMULA,CALCULATE,POSITION:REAL
OSHELL "DISPLAY 0C"
OFORMULA=(PI+2)/15
OCALCULATE=FORMULA
OSHELL "TMODE -PAUSE"
OFOR T=0 TO 100
OCALCULATE=CALCULATE+FORMULA
OPOSITION=INT(SIN(CALCULATE)*10+16)
OPRINT TAH(POSITION); "*"
ONEXT T
OSHELL "TMODE PAUSE"
REND


BASIC09 Reference

POKE Stores a value in a memory location

Syntax: POKE mem, value

Function: Stores a value at the specified memory address, relative to the current process's address space. Mem is an absolute address at which BASIC09 stores a byte type value. POKE is the complement of the PEEK statement.


You should use care when using POKE. Because it changes the value in memory, a POKE to the wrong portion of memory could cause OS-9, BASIC09, or your procedures to malfunction until you reboot the system.

See also ADDR.

Parameters:
mem An integer value representing the location of
the memory byte you want to change.
value The value to store in the specified memory
location.
Examples:

POKE 1 5250 , 1 3

11-116
                BASIC09 Command Reference / 11


Sample Program:

This procedure asks you to type a phrase in uppercase characters. It then uses ADDR to locate the area in memory where BASIC09 stores the phrase. Next, it reads each character from memory, converts it to lowercase if necessary, and uses POKE to store the new value back in the same location. When the procedure next displays the contents of the phrase, it is all lowercase.

PROCEDURE lowercase ODIM LOC,T:INTEGER; PHRASE:STRINGL80J OPRINT "Type a phrase in UPPERCASE and I'll make it lowercase." DINPUT PHRASE OLOC=ADDRCPHRASE) OFOR T=LOC TO LOC+LENCPHRASE) OX=PEEKCT) OIF X32 AND X<91 THEN OX=X+32 OPOKE T, X OENDI F ONE XT T OPRINT PHRASE REND

11-117
BASIC09 Reference

POS Returns cursor's column position

Syntax: POS

Function: Returns the current column position of the cursor. Parameters: None Examples:

PRINT POS

Sample Program:

This procedure is a simple typing program that uses POS to make sure that words are not split when you type to the end of the screen. After you type 25 characters on a line, the procedure breaks the line at the next space character.

PROCEDURE wordwrap
ODIM CHARACTER:STRINGf1J
OPRINT USING "S32^"; "Word Wrap Program"
OPRINT USING "S32^"; "Press LCTRLILCl to Exit"
OPRINT
OSHELL "TMODE -ECHO"
OWHILE CHARACTER<>" " DO
OGET *1 ,CHARACTER
OPRINT CHARACTER;
OIF POS>25 AND CHARACTER=" " THEN
OPRINT CHR$C13)
REND I F
OENDWHILE
OSHELL "TMODE ECHO"
REND

11-118
        BASIC09 Command Reference l 11


PRINT Displays text

Syntax: PRINT [#path] [TAB(pos);] data[;data...]

Function: Prints numeric or string data on the video display unless another path is specified.


Parameters:

path The number corresponding to an opened device
or file. If you do not specify path, the default
is # 1, the video screen (standard output
device). To print to another device or file, first
OPEN a path to that file or device (see
OPEN).
pos A column number that tells TAB where to
begin printing. Specify any number from 0 to
the width of your video display.
data Any numeric or string constant or variable.
Enclose string constants within quotation
marks. All data items must be separated by a
semicolon or comma.
Notes:

    · If you specify more than one data item in the statement, separate them with commas or semicolons.


    · If you use commas, PRINT automatically advances to the next tab zone before printing the next item. In BASIC09, tab zones are 16 characters apart.


    · If you use semicolons or spaces to separate data items, BASIC09 prints the items without any spaces between them. BASIC09 begins the next print item immediately following the end of the last print item.


    · If you end a print item without any trailing punctuation, PRINT begins printing at the beginning of the next line.


                                11-119

BASIC09 Reference

If the data being printed is longer than the display screen width, PRINT moves to the next line and continues printing the data.


TAB causes BASIC09 to begin displaying the specified data at the column position specified by TAB. If the output line is already past the specified TAB position, PRINT ignores TAB.


You can concatenate items for printing using the plus (+ symbol, for example: print "hello "+name$+" +lastname$.


PRINT displays REAL numbers with nine or fewer digits in regular format. It displays REAL numbers with more than nine digits in exponential format. For example, 1073741824 is displayed as 1 . 0 7 3 7 41 8 2 E + 0 9.


You must enclose string constants within quotation marks.

Examples:

PRINT A$

PRINT "Menu Items"

PRINT COUNT

PRINT VALUE,TEMP+Cn/2.5),LOCATION$
PRINT #PRINTER-PATH,"The result i5 ";NUMBER
PRINT #OUTPATH FMT$,COUNT,VALUE

PRINT "what

i5"+NAME$+`5 age? ";

PRINT "INDEX:

";I;TAHC25);"VALUE

";VALUE

11-120
        BASIC09 Command Reference / 11


Sample Program:

This procedure asks you to type a word or phrase, then displays it backwards by reading each character from end to beginning and using PRINT to display it on the screen.

PROCEDURE reverse ODIM PHRASE,TITLE:STRING; T,HEGIN:INTEGER ODIM INSTRUCTIONS:STRINGL431 OTITLE="Word Reversing Program" pINSTRUCTIONS="Type a word or phrase you want to reverse: " OPRINT TITLE
pPRINT " "
OWHILE PHRASE<),'"' DO
OPRINT
OPRINT INSTRUCTIONS
OINPUT PHRASE
OHEGIN=LENCPHRASE)
OPRINT "This is how your phrase looks backwards:"
OFOR T=BEGIN TO 1 STEP -1
OPRINT MID$CPHRASE,T,1);
ONEXT T
OPR I NT
DENDWHILE
REND

11-121
BASIC09 Reference

PRINT USING Displays formatted text

Syntax: PRINT [#path] USING [format,] data[;data...]

Function: Prints data using a format you specify. This statement is especially useful for printing report headings, accounting reports, checks, or any document requiring a specific format. USING is actually an extension of the PRINT statement; therefore, the same rules that apply to the PRINT statement also apply to the PRINT USING statement (see PRINT).

Parameters:

path The number corresponding to an opened device
or file. If you do not specify pith, the default
is # 1, the video screen (standard output
device). To print to another device or file, first
OPEN a path to that file or device (see
OPEN).
format An expression specifying the arrangement of
the displayed data.
data Any numeric or string constant or variable.
Always enclose string constants within quota
tion marks. Each data item must be separated
by semicolons or commas.
Notes:

Each PRINT USING format specifier begins with a single identifier letter that specifies the type of format, as shown in the following table:

B Boolean format
E exponential format
H hexadecimal format r~
I integer format
R real format
S string format

11-122
                    BASIC09 Command Reference / 11


    Follow the identifier letter with a constant number that specifies the field width. This number indicates the exact number of print

,,i-~ columns the output occupies. It must allow for both the data and
      any overhead characters, such as sign characters, decimal points,

      exponents, and so on.


      Optionally, you can add a justification indicator to the format expression. The indicators are <, >, and ^. The meaning of these indicators varies, depending on the format type in which you use them. See the format type descriptions for specific information.


      Note: Do not use any spaces within format expressions.


      The following are the format type descriptions:


      Real


      Use this format for real, integer, or byte type numbers. The total field width specification must include two overhead positions for the sign and decimal point. The field width has two parts, separated by a period. The first part specifies the integer portion of the field. The second part specifies how many fractional digits to

,~^ display to the right of the decimal point.

      If a number has more significant digits than the field allows, BASIC09 uses the undisplayed digits to round the number within the correct field width.


      The justification modes are:


          < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator.


      > Right justify with leading spaces and sign.


          Right justify with leading spaces and trailing sign (financial format).


      Some examples and their results are:


      PRINT USING 1IR8.2<11,5678.123 5678.12

      PRINT USING 1IR8.2>11,5678.123 5678.12

      PRINT USING "R8.2>",12.3 12.30

      PRINT USING "R8.2>",-555.9 -555.90

      PRINT USING "R10.2^",-6722.4599 6722.46-


                                    11-123

BASIC09 Reference

Exponential

Use this format to display real, integer, or byte values in the scientific notation format-using a mantissa and decimal exponent. The field has two parts: the first part must allow for six overhead positions for the mantissa sign, decimal point, and exponent characters.

The justification modes are:

      < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator.

      Right justify with leading spaces and sign.

Some examples and their results are:

PRINT USING "E1 2. 3",1 234.567 1.235E+03
PRINT USING "E13.6>",-.001234 -1.234000E-03
PRINT USING "E18. 5>",1 23456789 1.23457E+08
Integer

Use this format to display integer, byte, or real type numbers in
an integer or byte format. The field width must allow for one
position of overhead for the sign.
The justification modes are:

      < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator.

      Right justify with leading spaces and sign.

" Right justify with leading sign and zeroes. Some examples and their results are:

PRINT USING "I4<",10 10
PRINT USING "I4<",10 10
PRINT USING "I4^",-10 -010

Hexadecimal

Use this format to display any data type in hexadecimal notation. The field width specification determines the number of hexadecimal characters BASIC09 displays. If the data to display is string type, this function displays the ASCII value of each character in hexadecimal.


11-124
                BASIC09 Command Reference / 11


The justification modes are:

    < Left justify with trailing spaces. This is the default if you omit a justification indicator.


    Right justify with leading spaces.


^ Center digits.

The number of bytes of memory used to represent data varies according to data type. The following chart suggests field widths for specific data types:


Memory Field Width
Type Bytes To Specify
Boolean and Byte 1 2
Integer 2 4
Real 5 10
String 1 per 2 times the string
character length

Some examples and their results are:

PRINT USING "H4",100 0064
PRINT USING "H4",-1 FFFF
PRINT USING "H81%--,--ABC" 414243

String

Use this format to display string data of any length. The field width specifies the total field size. If the string to display is shorter than the field size, PRINT USING pads it with spaces according to the justification mode. If the string to display is longer than the specified field width, PRINT USING truncates the right portion of the string.


The justification modes are:

      < Left justify with trailing spaces. This is the default if you omit a justification indicator.


      Right justify with leading spaces.


^ Center characters.

                                11-125

BASIC09 Reference

Some examples and their results are:

PRINT USING "S9<","HELLO" HELLO
PRINT USING "S9>","HELLO" HELLO
PRINT USING "S9^","HELLO" HELLO
Boolean

Use this format to display Boolean expression results. BASIC09
converts the result of the expression to the strings "True" or
"False." The format and results are identical to STRING formats.
The justification modes are:

      < Left justify with trailing spaces. This is the default if you omit a justifcation indicator.

> Right justify with leading spaces.
" Center characters.
If A = 5 and B = 6, some examples and their results are:

PRINT USING "B9<",A<B True

PRINT USING "B9>",A>B Fa15e

PRINT USING "B9"",A=B Fa15e

Control Specifiers You can also use control specifiers within PRINT USING formats. The three specifiers are:

Tn Tab. n specifies a tab column at which to display
the next data.
Xn Spaces. n specifies a number of spaces to insert.
`text' Constant string. text is a string that is constant to
the format.
An example and its result is:

PRINT USING "'Addre55',X1,H4,X4,'Data',X1,H2",

1 000 ,1 00
Address 03E8 Data 64

11-126