RTR logo

R. T. RUSSELL

BBC BASIC (86) Manual



PRINT#

P.#

A statement which writes the internal form of a value out to a data file.
PRINT#E,A,B,C,D$,E$,F$
PRINT#4,prn$
The format of the variables as written to the file differs from the format used on the BBC Micro. All numeric values are written as five bytes of binary real data (see the Annex entitled Format of Program and Variables in Memory). Strings are written as the bytes in the string (in the correct order) plus a carriage return.

Before you use this statement, you must normally have opened a file using OPENOUT or OPENUP. PRINT# may alternatively be used with the AUX device (usually a serial port), which has the 'permanently open' handle = 3, or the PRN device (usually a parallel port) which has the 'permanently open' handle = 4.

You can use PRINT# to write data (numbers and strings) to a data file in the 'standard' manner. If you wish to 'pack' your data in a different way, you should use BPUT#. You can use PRINT# and BPUT# together to mix or modify the data format. For example, if you wish to write a 'compatible' text file, you could PRINT# the string and BPUT# a line-feed. This would write the string followed by a carriage-return and a line-feed to the file.

Remember, with BBCBASIC(86) the format of the file is completely under your control.

Syntax

PRINT#<numeric>{,<numeric>|<str>}

Associated Keywords

PRINT, OPENUP, OPENOUT, CLOSE#, INPUT#, BPUT#, BGET#, EXT#, PTR#, EOF#

PROC

A keyword used at the start of all user declared procedures. The first character of a procedure name can be an underline (or a number).

If there are spaces between the procedure name and the opening bracket of the parameter list (if any) they must be present both in the definition and the call. It's safer not to have spaces between the procedure name and the opening bracket.

A procedure may be defined with any number of parameters of any type.

A procedure definition is terminated by ENDPROC.

A procedure does not have to be declared before it is called.

Procedures are re-entrant and the parameters (arguments) are passed by value.

 10 INPUT"Number of discs "F
 20 PROC_hanoi(F,1,2,3)
 30 END
 40 :
 50 DEF PROC_hanoi(A,B,C,D)
 60 IF A=0 THEN ENDPROC
 70 PROC_hanoi(A-1,B,D,C)
 80 PRINT"Move disk ";A" from ";B" to ";C
 90 PROC_hanoi(A-1,D,C,B)
100 ENDPROC
See the Procedures and Functions sub-section for more details.

Syntax

PROC<name>[(<exp>{,<exp>})]

Associated Keywords

DEF, ENDPROC, LOCAL

PTR#

A pseudo-variable allowing the random-access pointer of the file whose file handle is its argument to be read and changed.
PTR#F=PTR#F+5 :REM Move pointer to next number
PTR#F=recordnumber*recordlength
Reading or writing (using BGET#, BPUT#, INPUT# or PRINT#) takes place at the current position of the pointer. The pointer is automatically updated following a read or write operation.

You can use PTR# to select which item in a file is to be read or written to next. In a random file (see the section on BBCBASIC(86) Disk Files) you use PTR# to select the record you wish to read or write.

If you wish to move about in a file using PTR# you will need to know the precise format of the data in the file.

A file opened with OPENUP may be extended by setting its pointer to its end (PTR#fnum = EXT#fnum) and then writing to it. If you do this, you must remember to CLOSE the file when you have finished with it in order to update the directory entry.

By using PTR# you have complete control over where you read and write data in a file. This is simple concept, but it may initially be difficult to grasp its many ramifications. The BBCBASIC(86) Disk Files section has a number of examples of the use of PTR#.

Syntax

PTR#<numeric>=<numeric>
<n-var>=PTR#<numeric>

Associated Keywords

OPENIN, OPENUP, OPENOUT, CLOSE#, PRINT#, INPUT#, BPUT#, BGET#, EXT#, EOF#

PUT

A statement to output data to an output port. Full 16-bit addressing is available.
PUT A,N :REM output N to port A.
This instruction gives direct access from BBCBASIC(86) to the computer's I/O hardware. Typically, you can use it to directly access I/O ports.

This extension to the language has not been approved by Acorn and cannot be guaranteed to remain unchanged in future releases of BBCBASIC(86).

Syntax

PUT <numeric>,<numeric>

Associated Keywords

GET

RAD

A function which converts degrees to radians.
X=RAD(Y)
X=SIN RAD(90)
Unlike humans, BBCBASIC(86) wants angles expressed in radians. You can use this function to convert an angle expressed in degrees to radians before using one of the angle functions (SIN, COS, etc).

Using RAD is equivalent to multiplying the degree value by PI/180, but the result is calculated internally to a greater accuracy.

See COS, SIN and TAN for further examples of the use of RAD.

Syntax

<n-var>=RAD<numeric>

Associated Keywords

DEG

READ

A statement which will assign to variables values read from the DATA statements in the program. Strings must be enclosed in double quotes if they have leading spaces or contain commas.
READ C,D,A$
In many of your programs, you will want to use data values which do not change frequently. Because these values are subject to some degree of change, you won't want to use constants. On the other hand, you won't want to input them every time you run the program either. You can get the best of both worlds by declaring these values in DATA statements at the beginning or end of your program and READing them into variables in your program.

A typical use for DATA and READ is a name and address list. The addresses won't change very often, but when they do you can easily amend the appropriate DATA statement.

See DATA for more details and an example of the use of DATA and READ.

Syntax

READ <n-var>|<s-var>{<n-var>|<s-var>}

Associated Keywords

DATA, RESTORE

REM

A statement that causes the rest of the line to be ignored thereby allowing comments to be included in a program.

You can use the REM statement to put remarks and comments in to your program to help you remember what the various bits of your program do. BBCBASIC(86) completely ignores anything on the line following a REM statement.

You will be able to get away without including any REMarks in simple programs. However, if you go back to a lengthy program after a couple of months you will find it very difficult to understand if you have not included any REMs.

If you include nothing else, include the name of the program, the date you last revised it and a revision number at the start of your program.

10 REM WSCONVERT REV 2.30
20 REM 5 AUG 84
30 REM Converts 'hard' carriage-returns to 'soft'
40 REM ones in preparation for use with WS.

Syntax

REM any text

Associated Keywords

None

RENUMBER

REN.

A command which will renumber the lines and correct the cross references inside a program.

The options are as for AUTO, but increments of greater than 255 are allowed.

You can specify both the new first number (n1) and/or the step size (s). The default for both the first number and the step size is 10. The two parameters should be separated by a comma or a hyphen.

RENUMBER
RENUMBER n1
RENUMBER n1,s
RENUMBER ,s
For example:
RENUMBERFirst number 10, step 10
RENUMBER 1000First number 1000, step 10
RENUMBER 1000-5  First number 1000, step 5
RENUMBER ,5First number 10, step 5
RENUMBER -5First number 10, step 5
RENUMBER produces error messages when a cross reference fails. The line number containing the failed cross-reference is renumbered and the line number in the error report is the new line number.

If you renumber a line containing an ON GOTO/GOSUB statement which has a calculated line number, RENUMBER will correctly cope with line numbers before the calculated line number. However, line numbers after the calculated line number will not be changed.

In the following example, the first two line numbers would be renumbered correctly, but the last two would be left unchanged.

ON action GOSUB 100,200,(type*10+300),400,500
RENUMBER may be used in a program, but it will exit to the command mode on completion.

Syntax

RENUMBER [<n-const>[,<n-const>]]

Associated Keywords

LIST

REPEAT

REP.

A statement which is the starting point of a REPEAT...UNTIL loop. A single REPEAT may have more than one UNTIL, but this is bad practice.

The purpose of a REPEAT...UNTIL loop is to make BBCBASIC(86) repeat a set number of instructions until some condition is satisfied.

REPEAT UNTIL GET=13 :REM wait for CR

X=0
REPEAT
  X=X+10
  PRINT "What do you think of it so far?"
UNTIL X>45
You must not exit a REPEAT...UNTIL loop with a GOTO. If you jump out of a loop with a GOTO (How could you!!!) you should jump back in. If you must jump out of the loop, you should use UNTIL TRUE to 'pop' the stack. For (a ghastly) example:
 10 i=1
 20 REPEAT: REM Print 1 to 100 unless
 30   I=I+1: REM interrupted by the
 40   PRINT i: REM space bar being pressed
 50   x=INKEY(0): REM Get a key
 60   IF x=32 THEN 110:REM exit if <SPACE>
 70 UNTIL i=100
 80 PRINT "****"
 90 END
100 :
110 UNTIL TRUE: REM Pop the stack
120 PRINT "Forced exit":REM Carry on with program
130 FOR j=1000 TO 1005
140   PRINT j
150 NEXT
160 END
See the keyword UNTIL for ways of using REPEAT...UNTIL loops to replace unconditional GOTOs for program looping.

See the sub-section on Program Flow Control in the General Information section for more details on the working of the program stack.

Syntax

REPEAT

Associated Keywords

UNTIL

REPORT

A statement which prints out the error string associated with the last error which occurred.

You can use this statement within your own error handling routines to print out an error message for those errors you are not able to cope with.

The example below is an error handling routine designed to cope only with the <ESCAPE> key being pressed. All other errors are reported and the program terminated.

  10 ON ERROR GOTO 1000
  20 .....
 970 .....
 980 END
 990 :
1000 PRINT
1010 IF ERR=17 THEN PRINT "<ESCAPE> ignored":GOTO 20
1020 REPORT:PRINT " at line ";ERL
See the sub-section on Error Handling and the keywords ERR, ERL and ON ERROR for more details.

Syntax

REPORT

Associated Keywords

ERR, ERL, ON ERROR

RESTORE

RES.

RESTORE can be used at any time in a program to set the line where DATA is read from.

RESTORE on its own resets the data pointer to the first data item in the program.

RESTORE followed by a parameter sets the data pointer to the first item of data in the specified line (or the next line containing a DATA statement if the specified line does not contain data). This optional parameter for RESTORE can specify a calculated line number.

RESTORE
RESTORE 100
RESTORE (10*A+20)
You can use RESTORE to reset the data pointer to the start of your data in order to re-use it. alternatively, you can have several DATA lists in your program and use RESTORE to set the data pointer to the appropriate list.

Syntax

RESTORE [<l-num>]
RESTORE [(<numeric>)]

Associated Keywords

READ, DATA

RETURN

R.

A statement causing a RETURN to the statement after the most recent GOSUB statement.

You use RETURN at the end of a subroutine to make BBCBASIC(86) return to the place in your program which originally 'called' the subroutine.

You may have more than one return statement in a subroutine, but it is preferable to have only one entry point and one exit point (RETURN).

Try to structure your program so you don't leave a subroutine with a GOTO. If you do, you should always return to the subroutine and exit via the RETURN statement. If you insist on using GOTO all over the place, you will end up confusing yourself and maybe confusing BBCBASIC(86) as well. The sub-section on Program Flow Control explains why.

Syntax

RETURN

Associated Keywords

GOSUB, ON GOSUB

RIGHT$

A string function which returns the right 'num' characters of the string. If there are insufficient characters in the string then all are returned.

There must not be any spaces between the RIGHT$ and the opening bracket.

A$=RIGHT$(A$,num)
A$=RIGHT$(A$,2)
A$=RIGHT$(LEFT$(A$,3),2)
For example,
10 name$="BBCBASIC(86)"
20 FOR i=3 TO 13
30   PRINT RIGHT$(name$,i)
40 NEXT
50 END
would print
86)
(86)
C(86)
IC(86)
SIC(86)
ASIC(86)
BASIC(86)
CBASIC(86)
BCBASIC(86)
BBCBASIC(86)
BBCBASIC(86)

Syntax

<s-var>=RIGHT$(<str>,<numeric>)

Associated Keywords

LEFT$, MID$

RND

A function which returns a random number. The type and range of the number returned depends upon the optional parameter.
RND returns a random integer 1 - &FFFFFFFF.
RND(n) returns an integer in the range 1 to n (n>1).
RND(1) returns a real number in the range 0.0 to .99999999.
If n is negative the pseudo random sequence generator is set to a number based on n and n is returned.

If n is 0 the last random number is returned in RND(1) format.

X=RND(1)
X%=RND
N=RND(6)
The random number generator is initialised by RUN (or CHAIN). Consequently, RND will return zero until the RUN (or CHAIN) command is first issued.

Syntax

<n-var>=RND[(<numeric>)]

Associated Keywords

None

RUN

Start execution of the program.
RUN
RUN is a statement and so programs can re-execute themselves.

All variables except @% to Z% are CLEARed by RUN.

If you want to start a program without clearing all the variables, you can use the statement

GOTO nnnn
where nnnn is number of the line at which you wish execution of the program to start.

RUN "filename" can be used as an alternative to CHAIN "filename".

Syntax

RUN

Associated Keywords

NEW, OLD, LIST, CHAIN

SAVE

SA.

A statement which saves the current program area to a file, in internal (tokenised) format.
SAVE "FRED.BBC"
SAVE A$
You use SAVE to save your program for use at a later time. The program must be given a name (file-specifier) and this name becomes the name of the file in which your program is saved.

The name (file-specifier) must follow the normal MS-DOS naming conventions. See the Operating System Interface section for a description of a file-specifier (name).

Unless a different extension is specified in the file-specifier, .BBC is automatically used. Thus,

SAVE "FRED"
would save the current program to a file called FRED.BBC in the current directory.

If you want to exclude the extension, include the full-stop in the file name, but don't follow it with anything. For example, to save a program to a file called 'FRED', type,

SAVE "FRED."

Syntax

SAVE <str>

Associated Keywords

LOAD, CHAIN

SGN

A function returning -1 for negative argument, 0 for zero argument and +1 for positive argument.
X=SGN(Y)
result=SGN(answer)
You can use this function to determine whether a number is positive, negative or zero.

SGN returns:

+1for positive numbers
0for zero
-1for negative numbers

Syntax

<n-var>=SGN(<numeric>)

Associated Keywords

ABS

SIN

A function giving the sine of its radian argument.
X=SIN(Y)
This function returns the sine of an angle. The angle must be expressed in radians, not degrees.

Whilst the computer is quite happy dealing with angles expressed in radians, you may prefer to express angles in degrees. You can use the RAD function to convert an angle from degrees to radians.

The example below sets Y to the sine of the angle 'degree_angle' expressed in degrees.

Y=SIN(RAD(degree_angle))

Syntax

<n-var>=SIN(<numeric>)

Associated Keywords

COS, TAN, ACS, ASN, ATN, DEG, RAD

SOUND

A statement which generates sounds using the internal loudspeaker.

Hardware limitations restrict the capabilities of the SOUND statement in BBCBASIC(86). Only one sound channel is available, the amplitude of the sound cannot be controlled and there is no 'noise' capability.

Despite the limitations mentioned above, the original format of the SOUND statement has been retained in order to maintain as much compatibility as possible with the BBC Micro.

The SOUND statement is followed by 4 parameters which specify the sound channel to be used, the loudness of the note (or the envelope number), the pitch of the note and how long the note is to last.

SOUND Channel,Loudness,Pitch,Duration

Channel

Only bit 4 has any effect. If set, the sound queue is flushed and the new sound is started immediately. The channel numbers as such are ignored. In order to maintain compatibility with the BBC Micro, the channel number used should be the same throughout the program.

Loudness

Values from -15 to -1 select a sound of constant amplitude and pitch. Zero selects silence. Values from 1 to 12 select a pitch envelope (see the keyword ENVELOPE for more details). For compatibility with the BBC Micro, a value of -15 should be used if you do not wish to specify an envelope.

Pitch

As with the BBC Micro, this selects the (initial) pitch of the note.

A value of 52 will give middle C.

To go up or down an octave, the Pitch must be changed by 48.

To go up a perfect 5th, the Pitch must be increased by 28.

Increasing the Pitch by 1 will increase the frequency of the note produced by 1/4 of a semitone.

 Octave Number
Note 12 34 56 7
B04896 144192240 
A# 4492 140188236 
A 4088 136184232 
G# 3684 132180228 
G 3280 128176224 
F# 2876 124172220 
F 2472 120168216 
E 2068 116164212 
D# 1664 112160208 
D 1260 108156204252
C# 856 104152200248
C 452 100148196244

Duration

The Duration can have any value between -1 and 254. Values in the range 0 to 254 give a note of duration of that number of twentieths of a second. A Duration of -1 will sound the note until you stop it. You can do this by pressing <Esc> or sending another note with the 'flush control' set to 1.

Examples

The example below simply generates two notes one after the other. The first note is middle C and it sounds for one (20/20) second. The second note is upper C; it sounds for two (40/20) seconds.
10 SOUND 1,-15,52,20
20 SOUND 1,-15,100,40
In the next example, the first SOUND statement (line 10) has a duration of -1. This will cause the note to continue until a SOUND statement with bit 4 of the channel number set cancels it (or <Esc> is pressed). Line 20 sets up another note and adds it to the sound queue. However, this note does not sound immediately because the first note is still sounding. Line 30 pauses for short period and then the SOUND command at line 40 is executed. The channel number has bit 4 set (add 16 to the channel number), so the sound queue is flushed by this command and its note (upper C) is sounded immediately. The sound added to the queue by line 20 was lost when the sound queue was flushed.
10 SOUND 1,-15,52,-1
20 SOUND 1,-15,56,50
30 TIME=0 : REPEAT UNTIL TIME>200
40 SOUND 17,-15,100,10
The final example uses an ENVELOPE. Line 10 sets up ENVELOPE No 1 and line 20 uses the envelope to make a SOUND. The sound produced is a slow 'warble' about the chosen note. Each step of the envelope is 0.1 (10/100) seconds. The pitch of the note will change by +5 Hz every step of section 1 of the envelope, by -5 Hz for every step of section 2, and by +5 Hz again for every step of section 3. Section 1 will last for 10 steps (1 second), section 2 for 20 (2 seconds) steps and section 3 for 10 steps. The second part of the ENVELOPE statement has been set so that a similar sound would be produced on a BBC Micro. The SOUND statement initially sounds upper C. The duration is -1, so you will need to press <Esc> to stop it.
10 ENVELOPE 1,10,5,-5,5,10,20,10,126,0,0,-126,126,0
20 SOUND 1,-15,100,-1
Try changing the length of each step (the second parameter - 10) and the number of steps per section (the 6th, 7th and 8th parameters - 10, 20, 10). Try changing the 2nd parameter so that the pitch envelope does not auto-repeat. (Set bit 7 by adding 128 to the current value.) Finally, try different durations and see how these affect the amount of the envelope used for the note.

Syntax

SOUND <numeric>,<numeric>,<numeric>,<numeric>

Associated Keywords

ENVELOPE

SPC

A statement which prints a number of spaces to the screen (or currently selected console output stream). The argument specifies the number of spaces (up to 255) to be printed.

SPC can only be used within a PRINT or INPUT statement.

PRINT DATE;SPC(6);SALARY

INPUT SPC(10) "What is your name ",name$

Syntax

PRINT SPC(<numeric>)
INPUT SPC(<numeric>)

Associated Keywords

TAB, PRINT, INPUT

SQR

A function returning the square root of its argument.
X=SQR(Y)
If you attempt to calculate the square root of a negative number, a '-ve root' error will occur. You could use error trapping to recover from this error, but it is better to check that the argument is not negative before using the SQR function.

Syntax

<n-var>=SQR(<numeric>)

Associated Keywords

None

STEP

S.

Part of the FOR statement, this optional section specifies step sizes other than 1.
FOR i=1 TO 20 STEP 5
The step may be positive or negative. STEP is optional; if it is omitted, a step size of +1 is assumed.

You can use this optional part of the FOR...TO...STEP...NEXT structure to specify the amount by which the FOR...NEXT loop control variable is changed each time round the loop. In the example below, the loop control variable, 'cost' starts as 20, ends at 5 and is changed by -5 each time round the loop.

10 FOR cost=20 TO 5 STEP -5
20   PRINT cost,cost*1.15
30 NEXT

Syntax

FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]

Associated Keywords

FOR, TO, NEXT

STOP

Syntactically identical to END, STOP also prints a message to the effect that the program has stopped.

You can use STOP at various places in your program to aid debugging. If your program is going wrong, you can place STOP commands at various points to see the path taken by your program. (TRACE is generally a more useful aid to tracing a program's flow unless you are using formatted screen displays.)

Once your program has STOPped you can investigate the values of the variables to find out why things happened the way they did.

STOP DOES NOT CLOSE DATA FILES. If you use STOP to exit a program for debugging, CLOSE all the data files before RUNning the program again. If you don't you will get some most peculiar error messages.

Syntax

STOP

Associated Keywords

END

STR$

A string function which returns the string form of the numeric argument as it would have been printed.

If the most significant byte of @% is not zero, STR$ uses the current @% description when generating the string. If it is zero (the initial value) then the G9 format (see PRINT) is used.

If STR$ is followed by ~ (tilde) then a hexadecimal conversion is carried out.

A$=STR$(PI)
B$=STR$~(100) :REM B$ will be "64"
The opposite function to STR$ is performed by the VAL function.

Syntax

<s-var>=STR$[~](<numeric>)

Associated Keywords

VAL, PRINT

STRING$

A function returning N concatenations of a string.
A$=STRING$(N,"hello")
B$=STRING$(10,"-*-")
C$=STRING$(Z%,S$)
You can use this function to print repeated copies of a string. It is useful for printing headings or underlinings. The last example for PRINT uses the STRING$ function to print the column numbers across the page. For example,
PRINT STRING$(4,"-=*=-")
would print
-=*=--=*=--=*=--=*=-
and
PRINT STRING$(3,"0123456789")
would print
012345678901234567890123456789

Syntax

<s-var>=STRING$(<numeric>,<str>)

Associated Keywords

None

TAB

A keyword available in PRINT or INPUT.

There are two versions of TAB: TAB(X) and TAB(X,Y) and they are effectively two different keywords.

TAB(X) is a printer orientated statement. The number of printable characters since the last new-line (COUNT) is compared with X. If X is equal or greater than COUNT, sufficient spaces to make them equal are printed. These spaces will overwrite any characters which may already be on the screen. If X is less than COUNT, a new-line will be printed first.

TAB(X,Y) is a screen orientated statement. It will move the cursor on the screen to character cell X,Y (column X, row Y) if possible. No characters are overwritten and COUNT is NOT updated. Consequently, a TAB(X,Y) followed by a TAB(X) will give unpredictable (at first glance) results.

The leftmost column is column 0 and the top of the screen is row 0.

PRINT TAB(10);A$
PRINT TAB(X,Y);B$

Syntax

PRINT TAB(<numeric>[,<numeric>])
INPUT TAB(<numeric>[,<numeric>])

Associated Keywords

POS, VPOS, PRINT, INPUT

TAN

T.

A function giving the tangent of its radian argument.
X = TAN(Y)
This function returns the tangent of an angle. The angle must be expressed in radians, not degrees.

Whilst the computer is quite happy dealing with angles expressed in radians, you may prefer to express angles in degrees. You can use the RAD function to convert an angle from degrees to radians.

The example below sets Y to the tangent of the angle 'degree_angle' expressed in degrees.

Y=TAN(RAD(degree_angle))

Syntax

<n-var>=TAN<numeric>

Associated Keywords

COS, SIN, ACS, ATN, ASN, DEG, RAD

THEN

TH.

An optional part of the IF... THEN ... ELSE statement. It introduces the action to be taken if the testable condition evaluates to TRUE.
IF A=B THEN 3000
IF A=B THEN PRINT "Equal" ELSE PRINT "Help"
You need to use THEN if it is followed by: or you wish to exit from a function as a result of the test. This is because BBCBASIC(86) can't work out what you mean in these circumstances if you leave the THEN out.
IF A=B PRINT "Equal" ELSE PRINT "Help"
DEF FN_test(num)
IF a=b THEN =num: REM THEN required on this line
=num/256

Syntax

IF <t-cond> THEN <stmt>{:<stmt>} [ELSE <stmt>{:<stmt>}]

Associated Keywords

IF, ELSE

TIME

TI.

A pseudo-variable which reads and sets the elapsed time clock.
X=TIME
TIME=100
You can use TIME to set and read BBCBASIC(86)'s internal clock. The value of the clock is returned in centi-seconds (one-hundredths of a second) and it is quite accurate. However, the clock is only updated about 18 times per second; each update adding 5 or 6 to the elapsed time count. For this reason, a delay loop such as REPEAT UNTIL TIME=T is likely to fail. The compound condition test REPEAT UNTIL TIME >=T should always be used.

Exiting from BBCBASIC(86) will turn the clock off and reset it.

The following example is a simple program to provide a 24 hour clock. Lines 20 to 40 get the correct time, lines 50 and 60 calculate the number of centi-seconds and set TIME, and lines 110 to 130 convert the value in TIME to hours, minutes and seconds. Line 90 stops the time being printed unless it has changed by at least one second.

 10 CLS
 20 INPUT "HOURS ",H
 30 INPUT "MINUTES ",M
 40 INPUT "SECONDS ",S
 50 PRINT "PUSH ANY KEY TO SET THE TIME ";:X=GET
 60 TIME=((H*60+M)*60+S)*100
 70 T=0
 80 REPEAT
 90   IF TIME DIV 100=T DIV 100 THEN 150
100   T=TIME
110   S=(T DIV 100) MOD 60
120   M=(T DIV 6000) MOD 60
130   H=(T DIV 360000) MOD 24
140   PRINT TAB(0,23) H;":";M;":";S;
150 UNTIL FALSE

Syntax

TIME=<numeric>
<n-var>=TIME

Associated Keywords

TIME$

TIME$

A 24 character long string pseudo-variable which reads and sets the system clock. The format of the character string is:

Day.dd Mon yyyy,hh:mm:ss

Where:

Day is the day of the week (Mon, Tue, etc).
ddis the day of the month (01, 02, etc).
Monis the abbreviated month name (Jan, Feb ,etc).
yyyy   is the year (1986, 1987, etc).
hhis hours (00 to 23).
mmis minutes (00 to 59).
ssis seconds (00 to 59).
The format is similar to that used on the Master Series BBC Micro except that the full-stop and comma are exchanged.
clock$=TIME$
TIME$="Sun.02 Feb 1986,18:33:30"
The time, date or both time and date may be set as shown below.
TIME$="Day.dd Mon yyyy"           sets the date.
TIME$="hh:mm:ss"                  sets the time.
TIME$="Day.dd Mon yyyy,hh:mm:ss"  sets date & time.
When setting the clock, the day of the week is ignored and may be omitted.

The first example below sets only the date and the second sets the date and the time.

TIME$="02 Feb 1986"

clock$="Mon.03 Feb 1986,22:31:15"
TIME$=clock$
No error is reported if the format is not accurately adhered to, however the clock may be set incorrectly.

Syntax

TIME$=<str>
<s-var>=TIME$

Associated Keywords

TIME

TO

The part of the FOR ... TO ... STEP statement which introduces the terminating value for the loop. When the loop control variable exceeds the value following 'TO' the loop is terminated.

For example,

10 FOR i=1 TO 5 STEP 1.5
20   PRINT i
30   NEXT
40 PRINT "**********"
50 PRINT i
will print
         1
       2.5
         4
**********
       5.5
Irrespective of the initial value of the loop control variable and the specified terminating value, the loop will execute at least once. For example,
10 FOR i= 20 TO 10
20   PRINT i
30 NEXT
will print
        20

Syntax

FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]

Associated Keywords

FOR, NEXT, STEP

TOP

A function which returns the value of the first free location after the end of the current program.

The length of your program is given by TOP-PAGE.

PRINT TOP-PAGE

Syntax

<n-var>=TOP

Associated Keywords

PAGE, HIMEM, LOMEM

TRACE

TR.

TRACE ON causes the interpreter to print executed line numbers when it encounters them.

TRACE X sets a limit on the size of line numbers which will be printed out. Only those line numbers less than X will appear. If you are careful and place all your subroutines at the end of the main program, you can display the main structure of the program without cluttering up the trace with the subroutines.

TRACE OFF turns trace off. TRACE is also turned off if an error is reported or you press <Esc>.

Line numbers are printed as the line is entered. For example,

10 FOR Z=0 TO 2:Q=Q*Z:NEXT
20 END
would trace as
[10] [20] >_
whereas
10 FOR Z=0 TO 2
20   Q=Q*Z:NEXT
30 END
would trace as
[10] [20] [20] [20] [30] >_
and
10 FOR Z=0 TO 3
20 Q=Q*Z
30 NEXT
40 END
would trace as
[10] [20] [30] [20] [30] [20] [30] [40] >_

Syntax

TRACE ON|OFF|<l-num>
TRACE ON|OFF|(<numeric>)

Associated Keywords

None

TRUE

A function returning the value -1.
 10 flag=FALSE
....
100 IF answer$=correct$ flag=TRUE
....
150 IF flag PROC_got_it_right ELSE PROC_wrong
BBCBASIC(86) does not have true Boolean variables. Instead, numeric variables are used and their value is interpreted in a 'logical' manner. A value of 0 is interpreted as false and NOT FALSE (in other words, NOT 0 (= -1)) is interpreted as TRUE.

In practice, any value other than zero is considered TRUE. This can lead to confusion; see the keyword NOT for details.

See the Variables sub-section for more details on Boolean variables and the keyword AND for logical tests and their results.

Syntax

<n-var>=TRUE

Associated Keywords

FALSE

UNTIL

U.

The part of the REPEAT ... UNTIL structure which signifies its end.

You can use a REPEAT...UNTIL loop to repeat a set of program instructions until some condition is met.

If the condition associated with the UNTIL statement is never met, the loop will execute for ever. (At least, until <Esc> is pressed or some other error occurs.)

The following example will continually ask for a number and print its square. The only way to stop it is by pressing <Esc> or forcing a 'Too big' error.

10 z=1
20 REPEAT
30   INPUT "Enter a number " num
40   PRINT "The square of ";num;" is ";num*num
50 UNTIL z=0
Since the result of the test z=0 is ALWAYS FALSE, we can replace z=0 with FALSE. The program now becomes:
20 REPEAT
30   INPUT "Enter a number " num
40   PRINT "The square of ";num;" is ";num*num
50 UNTIL FALSE
This is a much neater way of unconditionally looping than using a GOTO statement. The program executes at least as fast and the section of program within the loop is highlighted by the indentation.

See the keyword REPEAT for more details on REPEAT...UNTIL loops. See the Variables sub-section for more details on Boolean variables and the keyword AND for logical tests and their results.

Syntax

UNTIL <t-cond>

Associated Keywords

REPEAT

USR

A function which allows a machine code routine to return a value directly.

There are significant differences between BBCBASIC and BIGBASIC.

USR calls the machine code subroutine whose start address is its argument. Prior to calling the subroutine, The processor's AX, BX, CX and DX registers are initialised to the least significant words of A%, B%, C% and D% respectively (see also CALL). FLAGS is initialised to the least significant word of F%. However, you cannot disable interrupts nor enter single-step mode by setting F% to an appropriate value because this could be dangerous.

The four segment registers (CS, DS, SS and ES) are all set to the address of BBCBASIC's data segment (not BIGBASIC).

Your machine-code routine MUST return to BBCBASIC(86) with a far return (RETF), not a simple RET instruction.

USR provides you with a way of calling a machine code routine which is designed to return one integer value. Parameters are passed via the processor's registers and the machine code routine returns a 32-bit integer result composed of the processor's DX and AX registers. The DX register forms the most significant word of the result.

X=USR(lift_down)
Unlike CALL, USR returns a result. Consequently, you must assign the result to a variable. It may help your understanding if you look upon CALL as the machine code equivalent to a PROCedure and USR as the equivalent to Function.

Operating System Interface

USR and CALL operate differently when addresses in the range &FF00 to &FFFF are used. See the Operating System Interface section for more details.

Syntax

<n-var>=USR(<numeric>)

Associated Keywords

CALL

VAL

A function which converts a character string representing a number into numeric form.
X=VAL(A$)
VAL makes the best sense it can of its argument. If the argument starts with numeric characters (with or without a preceding sign), VAL will work from left to right until it meets a non numeric character. It will then 'give up' and return what it has got so far. If it can't make any sense of its argument, it returns zero.

For example,

PRINT VAL("-123.45.67ABC")
would print
-123.45
and
PRINT VAL("A+123.45")
would print
0
VAL will NOT work with hexadecimal numbers. You must use EVAL to convert hexadecimal number strings.

Syntax

<n-var>=VAL(<str>)

Associated Keywords

STR$, EVAL

VDU

V.

A statement which takes a list of numeric arguments and sends their least-significant bytes as characters to the current 'output stream' (see *OPT).

A 16-bit value can be sent if the value is followed by a ';'. It is sent as a pair of characters, least significant byte first.

VDU 8,8 :REM cursor left two places.
VDU &0A0D;&0A0D; :REM CRLF twice
The bytes sent using the VDU statement do not contribute to the value of COUNT, but may well change POS and VPOS.

You can use VDU to send characters direct to the current output stream without having to use a PRINT statement. It offers a convenient way of sending a number of control characters to the console or printer.

BBC Micro VDU Emulation

When the default output stream is selected (*OPT 0), all the console output is passed to a software emulation of the BBC Micro's VDU driver. The VDU codes then perform a function as similar as possible to those of the BBC Micro. The function of the various VDU codes when using the default output stream are described in the VDU Emulator section.

Syntax

VDU <numeric>{,|;<numeric>}[;]

Associated Keywords

CHR$

VPOS

A function returning the vertical cursor position. The top of the screen is line 0.
Y=VPOS
You can use VPOS in conjunction with POS to return to the present position on the screen after printing a message somewhere else. The example below is a procedure for printing a 'status' message at line 23. The cursor is returned to its previous position after the message has been printed.
1000 DEF PROC_message(message$)
1010 LOCAL x,y
1020 x=POS
1030 y=VPOS
1040 PRINT TAB(0,23) CHR$(7);message$;
1050 PRINT TAB(x,y);
1060 ENDPROC

Syntax

<n-var>=VPOS

Associated Keywords

POS

WIDTH

W.

A statement controlling output overall field width.
WIDTH 80
If the specified width is zero (the initial value) the interpreter will not attempt to control the overall field width.

WIDTH n will cause the interpreter to force a new line after n MOD 256 characters have been printed.

WIDTH also affects the output to the printer.

Syntax

WIDTH <numeric>

Associated Keywords

COUNT

Left CONTENTS

CONTINUE Right


Best viewed with Any Browser Valid HTML 3.2!
© Doug Mounter and Richard Russell