BASIC09 Command Reference l 11
PROCEDURE half5ine
ODIM FORMULA,CALCULATE,POSITION:REAL
OSHELL "DISPLAY 0C"
OFORMULA=CPI+2)/15
OCALCULATE=FORMULA
OSHELL "TMODE -PAUSE"
OFOR T=0 TO 100
OCALCULATE=CALCULATE+FORMULA
OPOSITION=INTCSINCCALCULATE)*10+16)
OIF SGNCSINCCALCULATE))>0 THEN
OPRINT TAHCPOSITION); "*"
OENDI F
ONEXT T
OSHELL "TMODE PAUSE"
REND
11-151
BASIC09 Reference
SHELL
Forks another shell
Syntax:
SHELL ["string"][ + "string"...][ + variable]
[ + variable...]
Function:
Executes OS-9 commands or programs from within
a BASIC09 procedure. Using SHELL, you can access OS-9
functions, including multiprogramming, utilities, commands,
terminal and input/output control, and so on.
When you use the SHELL command, OS-9 creates a new process to handle the commands you provide. If you specify an
operation, BASIC09 evaluates the expression and passes it to
the shell for execution. If you do not specify an operation,
BASIC09 temporarily halts, and the shell process displays
prompts and accepts commands in the normal manner. In this
case, press
CTRL BREAK
to return to BASIC09.
When the shell process terminates, BASIC09 becomes active
and resumes execution at the statement following the SHELL
statement.
Parameters:
string
Any OS-9 command or function. String con
stants must be enclosed in quotation marks.
Concatenate string constants and string vari
ables using a plus symbol (+ ).
variable
Any string variable containing an OS-9 com
mand or function.
11-152
BASIC09 Command Reference / 11
Examples:
SHELL "COPY FILE1 FILE2"
SHELL "COPY FILE1 FILE2&"
SHELL "COPY "+FILE$+" "+DIRNAME+"/"FILE$
SHELL "LIST DOCUMENT"
SHELL "KILL "+STR$CN)
Sample Program:
You must use this procedure with the GET sample program.
Using the two programs together enables you to copy all the files
from one directory to another directory. The GET sample program reads the files in a directory and stores them in a file
named Dirfile. This procedure reads the filenames from Dirfile
and uses SHELL to copy them to the directory you specify.
PROCEDURE copyutil
ODIM PATH,T,COUNT:INTEGER; FILE,JOB,DIRNAME:STRING
DOPEN #PATH , "d i r f i 1 e" :READ
OINPUT "Name of new directory...",DIRNAME
OSHELL "MAKDIR "+DIRNAME
OSHELL "LOAD COPY"
OWHILE NOTCEOFC#PATH)) DO
OREAD *PATH,FILE
OJOB-FILE+" "+DIRNAME+"/"+FI,LE
DON ERROR GOTO 10
OPRINT "COPY "; JOB
OSHELL "COPY "+JOB
1000N ERROR
OENDWHILE
OCLOSE #PATH
REND
11-153
BASIC09 Reference
SIN
Returns the sine of a number
Syntax:
SIN(n um ber)
Function:
Calculates the trigonometric sine of number. You
can use the DEG or RAD commands to cause number to represent a value in either degrees or radians. Unless you specify
DEG, the default is radians. SIN returns a real number.
Parameters:
number The angle of two sides of a triangle for which
you want to find the ratio.
Examples:
PRINT SIN(4S)
Sample Program:
This procedure calculates sine, cosine, and tangent values
for a number you type.
PROCEDURE ratiocalc
pDEG
ODIM ANGLE:REAL
DINPUT "Enter the angle of two sides of a
triangle...",ANGLE
OPRINT
OPRINT "Angle", "SINE", "COS I NEI' _IITANII
OPRINT
11------------_-----------------------------
-------------
OPRINT ANGLE,SIN(ANGLE),COS(ANGLE).,TAN(ANGLE)
OPRINT
REND
11-154
BASIC09 Command Reference / 1
1
SIZE
Returns the size of a data structure
Syntax:
SIZE(variable)
Function:
Returns the size in bytes of a variable, array, or
data structure. SIZE is especially useful with random access
files to determine the size of records to store in a file. You can
also use SIZE to determine the size of variable storage for
other purposes.
SIZE returns the size of assigned storage, not necessarily the
size of a string. For example, if you dimension a variable for
15 characters, and assign a 10-character string to it, SIZE
returns 15, not 10. SIZE returns the total size of arrays. That
is, it returns the number of elements multiplied by the size of
the elements.
Parameters:
variable
The variable, array, or data structure for
which you want to find the size.
Examples:
RECORDLENGTH = SIZE(A$)
PRINT "YOUR NAME IS STORED IN A "; SIZE(NAME$);
" CHARACTER STRING."
Sample Program:
This procedure creates a simple inventory, stored in a
file named Inventory. It uses SIZE to calculate the size
of each element to be stored in the file, and to move
the pointer to the beginning of each record's storage
space.
11-155
BASIC09 Reference
PROCEDURE inventory
pTYPE INV-ITEM=NAME:STRING125J; LIST,COST:REAL;
QTY: INTEGER
OD I M I NV-ARRAY( 1 0 0) : I NV-I TEM
OD I M WORK-REC : I NV-ITEM
ODIM PATH:BYTE
DON ERROR GOTO 10
ODELETE "inventory"
1000N ERROR
OCREATE #PATH,"inventory"
OWORK-REC. NAME="
OWORK-REC. L I ST= 0
OWORK-REC. COST= 0
OWORK-REC. QTY=0
OFOR N=1 TO 100
OPUT `PATH,WORK-REC
ONEXT N
OLOOP
DINPUT "Record number? ",recnum
OIF recnum<1 OR recnum>100 THEN
OPRINT
OPR I NT "End of Session"
OPRINT
OCLOSE #PATH
REND
DENDIF
OINPUT "Item name? ",WORK-REC.NAME
DINPUT "List price? ",WORK-REC.LIST
OINPUT "Cost price? ",WORK-REC.COST
OINPUT "Quantity? ",WORK-REC.QTY
OSEEK #PATH,(recnum-1)*SIZE(WORK-REC)
OPUT #PATH,WORK-REC
OENDLOOP
REND
11-156
BASIC09 Command Reference l 11
SQ
Returns the value of a number raised to the
power of 2
Syntax:
SQ(number)
Function:
Calculates the value of a number raised to the
power of 2.
Parameters:
number The number you want raised to the power of 2.
Examples:
PRINT SQC188)
PRINT PI·SQ(R)
Sample Program:
This procedure uses SQ in a formula that positions asterisks on
the screen in a sine wave pattern.
PROCEDURE
5inedown
DIM FORMULA,CALCULATE,POSITION:REAL
pSHELL "DISPLAY 0C"
FORMULA=CPI+2)/1 S
CALCULATE=FORMULA
SHELL "TMODE -PAUSE"
pFOR T=0 TO 200
pCALCULATE=CALCULATE+SQCFORMULA)
POSITION=INTCSINCCALCULATE)*12+16)
OPRINT TAHCPOSITION); "*"
NEXT T
SHELL "TMODE PAUSE"
REND
11-1s7
BASIC09 Reference
SQR/SQRT
Returns the square root of a
number
Syntax:
SQR(number)
SQRT(n um ber)
Function:
Calculates the square root of a number. SQR and
SQRT serve the same function.
Parameters:
number The number for which you want the square
root.
Examples:
PRINT SQR(188)
PRINT PI*SQRT(R)
Sample Program:
This procedure uses SQRT in a formula to position asterisks on
the screen in a sine wave pattern.
PROCEDURE sqrdown
ODIM FORMULA,CALCULATE,POSITION:REAL
OSHELL "DISPLAY 0C"
DFORMULA-P I / 1 5
OCALCULATE-FORMULA
OSHELL "TMODE -PAUSE"
OFOR T=0 TO 200
OCALCULATE-CALCULATE+SQRT(FORMULA).
pPOSITION-INT(SIN(CALCULATE)*12+16)
OPRINT TAH(POSITION); "*"
ONEXT T
pSHELL "TMODE PAUSE"
pEND
11-158
BASIC09 Command Reference / 11
STEP
Establishes the size of increments in a
FOR loop
Syntax:
FOR variable = init val TO end val [STEP value]
[procedure statements]
NEXT variable
Function:
STEP provides an increment value in a FOR/NEXT
loop. If you do not specify a STEP value, the loop steps in
increments of 1.
BASIC09 executes the lines following the FOR statement until
it encounters a NEXT statement. Then it either increases or
decreases the initial value by 1 (the default) or by the value
given by STEP. If you give the loop an initial value that is
greater than the final value, and specify a negative value for
STEP, the loop decreases from the initial value to the end
value.
Parameters:
variable
Any legal numeric variable name.
init val
Any numeric constant or variable.
end val
Any numeric constant or variable.
value
Any numeric constant or variable.
procedure
Procedure lines you want to be executed
statements
within the loop.
11-159
BASIC09 Reference
Examples:
FOR COUNTER = 1 to 100 STEP .S
PRINT COUNTER
NEXT COUNTER
FOR X = 1 0 TO 1 STEP -1
PRINT X
NEXT X
FOR TEST = A TO B STEP RATE
PRINT TEST
NEXT TEST
Sample Program:
This procedure reverses the order of characters in a word or
phrase you type. It uses STEP to decrement a counter that
points to each character in the string in reverse order.
PROCEDURE reverse
pDIM PHRASE:STRING; T,BEGIN:INTEGER
pPRINT "Type a word or phrase you want to
reverse:";
OPRINT
OINPUT PHRASE
OBEGIN=LENCPHRASE)
OPRINT "This is how your phrase looks backwards:"
OFOR T=BEGIN TO 1 STEP -1
OPRINT MID$CPHRASE,T,1);
ONEXT T
OPRINT
REND
11-160
BASIC09 Command Reference l 11
STOP
Terminates a procedure
Syntax:
STOP ["string"]
Function:
Causes a procedure to cease execution, print the
message "STOP Encountered", and return control to
BASIC09's command mode. You can also specify additional
text to display when BASIC09 encounters STOP.
Use stop when you want a procedure to terminate without
entering the DEBUG mode.
Parameters:
string Text to display when STOP executes.
Examples:
STOP "Program terminated b
fore completion."
IF RESPONSE = "Y" THEN STOP "Program terminated
at your request."
ENDIF
BASIC09 Reference
STR$
Converts numeric data to string data
Syntax: STR$(numbex)
Function:
Converts a numeric type to a string type. This lets
you display the number as a string or use string operators on
a number. The conversion replaces the numeric values with
the ASCII characters of the number. STR$ is the inverse of
the VAL function.
Parameters:
number Any numeric-type data.
Examples:
PRINT STRt(1010)
DIM I:INTEGER
I=44
PRINT STRtCI)
DIM H:HYTE
H=001
PRINT STRt(H)
DIM R:REAL
R=1234.56
PRINT STRi(R)
Sample Program:
This procedure calculates an exponential value, then adds the
necessary number of zeroes to convert it to standard notation. It
uses STR$ to convert the number you type to a string type value
so that it can use string functions to add the zeroes.
11-162
BASIC09 Command Reference / 11
PROCEDURE bignum
ODIM C,PLACES,H,SIGN:STRING; EX,COUNT,NEWCOUNT,
DECIMAL: INTEGER
ODIM NEW,ZERO,NEWEST:STRINGL100J
OCOUNT=-1
OZERO="000000000000000000000000000000000000"
ONEW="" NEWEST=""
OINPUT "What number do you want to raise to the
power of 14?...", NUM
DA=NUM"14
OH=STR$(A)
OEX=SUHSTR("E",H)
OSIGN=MID$(H,EX+1 ,1 )
OPLACES=RIGHT$(H,LEN(H)-EX-1)
OFOR T=1 TO LEN(H)
OC=MID$(H,T, 1 )
OIF C="." THEN
ODECIMAL=0
OGOTO 1 0
REND I F
ODECIMAL=DECIMAL+1
OIF C="E" THEN 100
ONEW=NEW+C
10ONEXT T
100ONEWCOUNT=VALCPLACES)-DECIMAL
ONEW=NEW+LEFT$(ZERO,NEWCOUNT+1)
OFOR T=LEN(NEW) TO 1 STEP -1
OCOUNT=COUNT+1
ONEWEST=MID$(NEW,T,1)+NEWEST
OIF MOD(COUNT,3)=2 AND T),1 THEN
ONEWEST=","+NEWEST
REND I F
ONEXT T
OPRINT NUM; " to the power of 14 = "; a
OPRINT "_ "; NEWEST
REND
11-163
BASIC09 Reference
SUBSTR
Searches for specified characters in
a string
Syntax:
SUBSTR(targetstringsearchstring)
Function:
Searches for the first occurrence of
targetstring
within
searchstring
and returns the numeric value of its location. SUBSTR counts the first character in
searchstring
as
character Number 1. Therefore, if you searched for the string
"worth" in the string "Fortworth", SUBSTR returns a value of
5.
If SUBSTR cannot find
targetstring,
it returns a value of 0.
Parameters:
targetstring
The group of characters you want to locate.
searchstring
The string in which you want to find
targetstring.
Examples:
PRINT SUBSTR("THREE","ONETWOTHREEFOURFIVESIX")
X=SUBSTR(" ",FULLNAME$)
Sample Program:
This procedure selects the last name from a string containing both a first name and a last name. It uses
SUBSTR to find the space between the two names in
order to determine where the last name begins.
11-164
BASIC09 Command Reference l 11
PROCEDURE la5tname
pDIM NAMES:STRING; LASTNAME:STRINGL101
pPRINT "Here are the last names:"
pFOR T=1 TO 1 0
DREAD NAMES
OPOINTER=SUHSTRC" ",NAMES)
OPOINTER=LENCNAMES)-POINTER
pLASTNAME=RIGHT$tNAMES,POINTER)
OPRINT LASTNAME
ONEXT T
ODATA "Joe Blonski","Mike Marvel","Hal
Skeemish","Fred Laungly"
ODATA "Jane Misty","Wendy Paston","Martha
Up5hong","Jacqueline Rivers"
ODATA "Su5y Reetmore","Wilson Creding"
REND
11-165
BASIC09 Reference
SYSCALL
Executes an OS-9 System Call
Syntax:
SYSCALL callcode registers
Function:
Lets you execute any OS-9 system call from
BASIC09. Use this command to directly manipulate your system or data or to directly access devices.
Be careful! Used improperly, SYSCALL can cause undesirable results you might unintentionally format a disk or
destroy disk or memory data. Before using SYSCALL, you
should be familiar with assembly language programming and
should understand the system call information in the OS-9
Technical Reference manual. The OS-9 Technical Reference
manual provides information about all OS-9 system calls.
To pass required register values to the SYSCALL command,
create a complex data structure that contains values for all
registers. Fbr example:
TYPE REGISTERS=CC,A,B,DP:HYTE; X,Y,U:INTEGER
DIM REGS:REGISTERS
DIM CALLCODE:BYTE
The complex data type REGISTERS contains values for all
registers. Unless you specifically assign values to variables
(for instance, REGS.CC, REGS.A, and REGS.B in the previous example), they contain random values. See the TYPE
command for further information.
Parameters:
callcode is the request code of the system call you wish
to use. All system call codes are referenced in
the OS-9
Technical Reference
manual.
registers is a list of the register entry values required
for the system call you are using.
Examples:
see "Sample Programs."
11-166
BASIC 09 Command Reference / 11
Sample Programs:
The following programs set up a data type (REGISTERS) for the
register variables. Before executing SYSCALL, the procedures
store the required register entry values in the complex data
structure REGS. The procedures also establish CALLCODE as a
variable to hold the request code of the system call you want to
use.
The Writecall procedure uses the string variable TEST to store
text that it writes to the screen through Path 0 (the standard
output path) using System Call $8A, I$Write. Before the procedure calls I$Write, it stores the appropriate path number (0) in
Register A. The ADDR command calculates the address of the
variable TEST, and the LEN command determines the length of
the variable. The procedure stores these two values in Registers
X and Y.
The Readcall uses System Call $8B, I$ReadLn to perform a
function that is the opposite of Writecall. Readcall establishes
TEST as a string variable into which it writes the characters
you type. Because the length of TEST is restricted to ten characters
(DIM TEST: STRING[ 1 0 1
), the terminal bell sounds if you
attempt to type more than 10 characters. Pressing [ENTER]
terminates the call and the procedure prints the contents of
TEST the characters you typed.
11-167
BASIC09
Reference
PROCEDURE WriteCall
OTYPE REGISTERS=CC,A,B,DP:BYTE; X,Y,U:INTEGER
ODIM REGS:REGISTERS
ODIM PATH,CALLCODE:BYTE
ODIM TEST:STRINGL50l
OTEST="This is a test of I$Write,,Sy5tem call
$8A..."
OREGS.A=0
OREGS.X=ADDRCTEST)
OREGS.Y=LENCTEST)
OCALLCODE=$8A
ORUN SYSCALLCCALLCODE,REGS)
OPRINT
REND
PROCEDURE Readcall
OTYPE REGISTERS=CC,A,B,DP:BYTE; X,Y,U:INTEGER
ODIM REGS:REGISTERS
ODIM PATH,CALLCODE:BYTE
ODIM TEST:STRINGf10l
OREGS.A=0
OREGS.X=ADDRCTEST)
DREGS . Y=1 0
OCALLCODE=$8B
ORUN SYSCALLCCALLCODE,REGS)
OPRINT
OPRINT TEST
REND
11-168
BASIC09 Command Reference l 11
TAB
Causes PRINT to jump to the specified
column
Syntax:
TAB(number)
Function:
Causes PRINT to display the next PRINT item to
display in the column specified by number. If the cursor is
already past the desired tab position, BASIC09 ignores TAB.
Use POS to determine the current cursor position when displaying characters on the screen.
Screen display columns are numbered from 1, the leftmost column, to a maximum of 255. The size of BASIC09 output
buffer varies according to the stack size.
You can also use TAB with PRINT USING statements.
,^ Parameters:
number The column at which you want PRINT to
begin.
Examples:
PRINT TAB(20);TITLE$
PRINT TAH(X);ITEMNUMBER;ITEM$
Sample Program:
This procedure uses asterisks to simulate a sine wave on the
screen. It uses TAB to position each asterisk in the proper
location.
11469
BASIC09 Reference
PROCEDURE 5inewave
pDIM FORMULA,CALCULATE,POSITION:REAL
OSHELL "DISPLAY 0C"
OFORMULA=CPI+2)/1 S
OCALCULATE=FORMULA
OSHELL "TMODE -PAUSE"
OFOR T=0 TO 200
OCALCULATE=CALCULATE+SQCFORMULA)
OPOSITION=INTCSINCCALCULATE)*12+16)
OPRINT TAHCPOSITION); "*"
ONEXT T
OSHELL "TMODE PAUSE"
REND
11-170
BASIC09 Command Reference l 11
TAN
Returns the tangent of a value
Syntax:
TAN(n um ber)
Function:
Calculates the trigonometric tangent of number.
Using DEG or RAD, you can specify the measure of the angle
(number) in either degrees or radians. Radians are the default
units.
Parameters:
number The angle for which you want to find the
tangent.
Examples:
PRINT TANC45)
Sample Program:
This procedure calculates sine, cosine, and tangent values for a
number you type.
PROCEDURE ratiocalc
ODEG
DIM ANGLE:REAL
pINPUT "Enter the angle of two sides of a
triangle...",ANGLE
pPRINT
pPRINT "Angle", "SINE","COSINE","TAN"
SPRINT ANGLE,SINCANGLE),COSCANGLE),TANCANGLE)
pPR I NT
pEND
BASIC09 Reference
TRIM$
Removes spaces from the end of a string
Syntax:
T RIM$(,string)
Function:
Removes any trailing spaces from the end of the
specified string. This function is particularly useful for trimming records you recover from a random access file.
Parameters:
string The string or string variable from which you
wish to remove trailing spaces.
Examples:
PRINT TRIM$(A$)
GET A$,B$,C$
PRINT TRIM$(A$),TRIM$(B$),TRIM$(C$)
Sample Program:
This program takes names you type and puts them in a
random access disk file. Because random access files use
the same amount of storage for each item, short names
are pfd with extra spaces. When reading the names
back from the file, the procedure uses TRIM$ to remove
these extra spaces.
PROCEDURE namestor
ODIM NAMES,TEMP1,NAME(100):STRINGL261; FIRST,LAST:
STRINGf15l; INITIAL:STRINGL1J
DDIM PATH,T:INTEGER
ONAMES=""
DON ERROR GOTO 10
FIDELETE "nameli5t"
100ON ERROR
OCREATE #PATH,"nameli5t":UPDATE
OFOR T=1 TO 1 00
[INA ME (T)
ONEXT T
OT = 0
11-172
BASIC09 Command Reference l 11
pL00P
DINPUT "First Name: ",FIRST
DEXITIF FIRST="" THEN
OCLOSE #PATH
OGOTO 1 0 0
OENDEXIT
OINPUT "Initial: ",INITIAL
OINPUT "Last: ",LAST
OT=T+ 1
ONAMECT)=FIRST+" "+INITIAL+" "+LAST
OPUT #PATH,NAMECT)
OSEEK #PATH,T*26
OENDLOOP
1000OPEN #PATH,"namelist":READ
OPRINT \ PRINT
OPRINT "Lastname","Firstname","Initial
OREM Print underline C40 characters)
OPRINT " -
OPRINT
OSEEK #PATH,O
OT = 0
OWHILE NOTCEOFC#PATH)) DO
OGET #PATH,NAMES
OT=T+ 1
ONAMES=TRIM$CNAMES)
OX=SUHSTRC" ",NAMES)
OFIRST=LEFT$CNAMES,X-1)
OTEMP1=RIGHT$CNAMES,LENCNAMES)-X+1)
OINITIAL=MID$CTEMP1 ,2,1 )
OLAST=RIGHT$CTEMP1,LENCTEMP1)-3)
OPRINT LAST,FIRST,INITIAL
OSEEK #PATH,T*26
DENDWHILE
OCLOSE #PATH
REND
11-173
BASIC09 Reference
TRON/TROFF
Turns on/off trace function
Syntax: TRON
TROFF
Function:
Turns on or off the BASIC09 trace mode. When
trace is turned on (TRON), BASIC09 decompiles and displays
each statement in a procedure before execution. BASIC09 also
displays the result of each expression after evaluation. This
function lets you follow program flow and is helpful in debugging and analyzing the execution of a procedure. After the
procedure is debugged, remove the TRON statement.
If you want to view only a portion of a procedure's execution,
surround that portion with TRON and TROFF. Tracing
begins immediately after the TRON statement and ends at
the TROFF statement. The rest of the program executes
normally.
Parameters:
None
Examples:
H$="00000000000000000000"+H$
N=1 +LEN(H$
FOR I=4 TO 1 STEP -1
TRON
N=N-4
A(I)=VAL(MID$(H$,N,4))
TROFF
NEXT I
11-174
BASIC09 Command Reference / 11
TRUE
Returns a Boolean TRUE value
tax:
variable = TRUE
Function:
TRUE is a Boolean function that always returns
True. You can use TRUE and FALSE to assign values to Boolean variables.
Parameters:
variable
The Boolean storage unit you want to set to
True.
Examples:
DIM TEST:HOOLEAN
TEST=TRUE
Sample Program:
This procedure asks five questions. If your answer is correct, it
stores the Boolean value TRUE in a Boolean type variable. If
your answer is incorrect, .it stores the Boolean value FALSE in
the variable.
PROCEDURE quiz
pDIM REPLY,VALUE:BOOLEAN; ANSWER:STRINGf1l;
QUESTION:STRINGL80J
pFOR T=1 TO 5
DREAD QUESTION,VALUE
pPRINT QUESTION
OPR I NT "CT) = TRUEE100000pCF) = FALSE"
OPRINT "Select T or F:OO";
OGET x1,ANSWER
OIF ANSWER="T" THEN
OREPLY=TRUE
,~` DELSE
OREPLY=FALSE
REND I F
OIF REPLY=VALUE THEN
OPRINT \ PRINT "That's Correct ...Good Show!"
DELSE
11-175
BASIC09 .Reference
pPRINT "Sorry, you're wrong ...Hetter Luck next
time."
DENDI F
OPRINT \ PRINT \ PRINT
ONEXT T
ODATA "In computer talk, CPU stands for Central
Packaging Unit.", FALSE
ODATA "The actual value of 64K is 65536
bytes.",TRUE
ODATA "The bits in a byte are normally numbered 0
through 7.",TRUE
ODATA "HASIC09 has four data types.",FALSE
ODATA "The LAND function is a Boolean type
operator.",FALSE
REND
11-176