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 BBC BASIC (Z80) 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 BBC BASIC (Z80) 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 BBC BASIC (Z80) 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.

PUT A,N :REM output N to port A.

This instruction gives direct access from BBC BASIC (Z80) to the computer’s I/O hardware. Typically, you can use it to directly access I/O ports.

Syntax

PUT <numeric>,<numeric>

Associated Keywords

GET

RAD

A function which converts degrees to radians.

X=RAD(Y)
X=SIN RAD(90)

Unlike humans, BBC BASIC (Z80) 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.

REM does not tokenise any statements within comments. This is to bring it inline with string literals for internationalisation.

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. BBC BASIC (Z80) 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:

|== |RENUMBER |First number 10, step 10 |RENUMBER 1000 |First number 1000, step 10 |RENUMBER 1000-5  ` |First number 1000, step 5 |`RENUMBER ,5 |First number 10, step 5 |RENUMBER -5 |First 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 BBC BASIC (Z80) 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 BBC BASIC (Z80) 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 BBC BASIC (Z80) 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$="BBC BASIC (Z80)"
20 FOR i=3 TO 13
30   PRINT RIGHT$(name$,i)
40 NEXT
50 END

would print

86)
(Z80)
C(Z80)
IC(Z80)
SIC(Z80)
ASIC(Z80)
BASIC (Z80)
CBASIC (Z80)
BCBASIC (Z80)
BBC BASIC (Z80)
BBC BASIC (Z80)

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 CP/M-80 naming conventions. See the Operating System Interface section for a description of a file-specifier (name).

The following file extensions are supported:

  • .BBC: LOAD and SAVE in BBC BASIC for Z80 tokenised format

  • .BAS: LOAD and SAVE in plain text format (also .TXT and .ASC)

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:

|== |+1 |for positive numbers |0 |for zero |-1 |for 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

Syntax: SOUND channel,volume,pitch,duration

Play a sound through the Agon Light buzzer and audio output jack

  • Channel: 0 to 2

  • Volume: 0 (off) to -15 (full volume)

  • Pitch: 0 to 255

  • Duration: -1 to 254 (duration in 20ths of a second, -1 = play forever)

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:

  • A line number.

IF a=b THEN 320
  • A 'star' (*) command.

IF a=b THEN *DIR
  • An assignment of a pseudo-variable.

IF a=b THEN TIME=0

or you wish to exit from a function as a result of the test. This is because BBC BASIC (Z80) 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 by accessing the ESP32 RTC data.

NB: This is a virtual string variable; at the moment only getting the time works. Setting is not yet implemented.

Example:

  10 REM CLOCK
  20 :
  30 CLS
  40 PRINT TAB(2,2); TIME$
  50 GOTO 40

Syntax

<n-var>=TIME$

Associated Keywords

None

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.

[source,console]
10 flag=FALSE

100 IF answer$=correct$ flag=TRUE

150 IF flag PROC_got_it_right ELSE PROC_wrong

BBC BASIC (Z80) 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.

USR calls the machine code subroutine whose start address is its argument. The processor’s A, B, C, D, E, F, H and L registers are initialised to the least significant words of A%, B%, C%, D%, E%, F%, H% and L% respectively (see also CALL).

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 HLH’L' registers.

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.

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.

The VDU commands on the Agon Light will be familiar to those who have coded on Acorn machines. Please refer to the [VDP wiki](https://github.com/breakintoprogram/agon-docs/wiki/VDP/ff9e72943455a90430c31c097fd7083616bc857e) for details on what VDU commands are supported.

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.

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