PRINT# |
P.# |
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.PRINT#E,A,B,C,D$,E$,F$ PRINT#4,prn$
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.
PRINT#<numeric>{,<numeric>|<str>}
PRINT, OPENUP, OPENOUT, CLOSE#, INPUT#, BPUT#, BGET#, EXT#, PTR#, EOF#
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.
See the Procedures and Functions sub-section for more details.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
PROC<name>[(<exp>{,<exp>})]
DEF, ENDPROC, LOCAL
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.PTR#F=PTR#F+5 :REM Move pointer to next number PTR#F=recordnumber*recordlength
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#.
PTR#<numeric>=<numeric> <n-var>=PTR#<numeric>
OPENIN, OPENUP, OPENOUT, CLOSE#, PRINT#, INPUT#, BPUT#, BGET#, EXT#, EOF#
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.PUT A,N :REM output N to port A.
This extension to the language has not been approved by Acorn and cannot be guaranteed to remain unchanged in future releases of BBCBASIC(86).
PUT <numeric>,<numeric>
GET
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).X=RAD(Y) X=SIN RAD(90)
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.
<n-var>=RAD<numeric>
DEG
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.READ C,D,A$
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.
READ <n-var>|<s-var>{<n-var>|<s-var>}
DATA, RESTORE
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.
REM any text
None
RENUMBER |
REN. |
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.
For example:RENUMBER RENUMBER n1 RENUMBER n1,s RENUMBER ,s
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.
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
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.
RENUMBER may be used in a program, but it will exit to the command mode on completion.ON action GOSUB 100,200,(type*10+300),400,500
RENUMBER [<n-const>[,<n-const>]]
LIST
REPEAT |
REP. |
The purpose of a REPEAT...UNTIL loop is to make BBCBASIC(86) repeat a set number of instructions until some condition is satisfied.
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: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
See the keyword UNTIL for ways of using REPEAT...UNTIL loops to replace unconditional GOTOs for program looping.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 sub-section on Program Flow Control in the General Information section for more details on the working of the program stack.
REPEAT
UNTIL
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.
See the sub-section on Error Handling and the keywords ERR, ERL and ON ERROR for more details.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
REPORT
ERR, ERL, ON ERROR
RESTORE |
RES. |
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.
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.RESTORE RESTORE 100 RESTORE (10*A+20)
RESTORE [<l-num>] RESTORE [(<numeric>)]
READ, DATA
RETURN |
R. |
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.
RETURN
GOSUB, ON GOSUB
There must not be any spaces between the RIGHT$ and the opening bracket.
For example,A$=RIGHT$(A$,num) A$=RIGHT$(A$,2) A$=RIGHT$(LEFT$(A$,3),2)
would print10 name$="BBCBASIC(86)" 20 FOR i=3 TO 13 30 PRINT RIGHT$(name$,i) 40 NEXT 50 END
86) (86) C(86) IC(86) SIC(86) ASIC(86) BASIC(86) CBASIC(86) BCBASIC(86) BBCBASIC(86) BBCBASIC(86)
<s-var>=RIGHT$(<str>,<numeric>)
LEFT$, MID$
If n is negative the pseudo random sequence generator is set to a number based on n and n is returned.
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 0 the last random number is returned in RND(1) format.
The random number generator is initialised by RUN (or CHAIN). Consequently, RND will return zero until the RUN (or CHAIN) command is first issued.X=RND(1) X%=RND N=RND(6)
<n-var>=RND[(<numeric>)]
None
RUN is a statement and so programs can re-execute themselves.RUN
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
where nnnn is number of the line at which you wish execution of the program to start.GOTO nnnn
RUN "filename" can be used as an alternative to CHAIN "filename".
RUN
NEW, OLD, LIST, CHAIN
SAVE |
SA. |
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.SAVE "FRED.BBC" SAVE A$
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,
would save the current program to a file called FRED.BBC in the current directory.SAVE "FRED"
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."
SAVE <str>
LOAD, CHAIN
You can use this function to determine whether a number is positive, negative or zero.X=SGN(Y) result=SGN(answer)
SGN returns:
+1 for positive numbers 0 for zero -1 for negative numbers
<n-var>=SGN(<numeric>)
ABS
This function returns the sine of an angle. The angle must be expressed in radians, not degrees.X=SIN(Y)
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))
<n-var>=SIN(<numeric>)
COS, TAN, ACS, ASN, ATN, DEG, RAD
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
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 1 2 3 4 5 6 7 B 0 48 96 144 192 240 A# 44 92 140 188 236 A 40 88 136 184 232 G# 36 84 132 180 228 G 32 80 128 176 224 F# 28 76 124 172 220 F 24 72 120 168 216 E 20 68 116 164 212 D# 16 64 112 160 208 D 12 60 108 156 204 252 C# 8 56 104 152 200 248 C 4 52 100 148 196 244
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,20 20 SOUND 1,-15,100,40
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 SOUND 1,-15,52,-1 20 SOUND 1,-15,56,50 30 TIME=0 : REPEAT UNTIL TIME>200 40 SOUND 17,-15,100,10
10 ENVELOPE 1,10,5,-5,5,10,20,10,126,0,0,-126,126,0Try 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.
20 SOUND 1,-15,100,-1
SOUND <numeric>,<numeric>,<numeric>,<numeric>
ENVELOPE
SPC can only be used within a PRINT or INPUT statement.
PRINT DATE;SPC(6);SALARY INPUT SPC(10) "What is your name ",name$
PRINT SPC(<numeric>) INPUT SPC(<numeric>)
TAB, PRINT, INPUT
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.X=SQR(Y)
<n-var>=SQR(<numeric>)
None
STEP |
S. |
The step may be positive or negative. STEP is optional; if it is omitted, a step size of +1 is assumed.FOR i=1 TO 20 STEP 5
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
FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]
FOR, TO, NEXT
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.
STOP
END
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.
The opposite function to STR$ is performed by the VAL function.A$=STR$(PI) B$=STR$~(100) :REM B$ will be "64"
<s-var>=STR$[~](<numeric>)
VAL, PRINT
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,A$=STRING$(N,"hello") B$=STRING$(10,"-*-") C$=STRING$(Z%,S$)
would printPRINT STRING$(4,"-=*=-")
and-=*=--=*=--=*=--=*=-
would printPRINT STRING$(3,"0123456789")
012345678901234567890123456789
<s-var>=STRING$(<numeric>,<str>)
None
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$
PRINT TAB(<numeric>[,<numeric>]) INPUT TAB(<numeric>[,<numeric>])
POS, VPOS, PRINT, INPUT
TAN |
T. |
This function returns the tangent of an angle. The angle must be expressed in radians, not degrees.X = TAN(Y)
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))
<n-var>=TAN<numeric>
COS, SIN, ACS, ATN, ASN, DEG, RAD
THEN |
TH. |
You need to use THEN if it is followed by:IF A=B THEN 3000 IF A=B THEN PRINT "Equal" ELSE PRINT "Help"
IF a=b THEN 320
IF a=b THEN *DIR
IF a=b THEN TIME=0
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
IF <t-cond> THEN <stmt>{:<stmt>} [ELSE <stmt>{:<stmt>}]
IF, ELSE
TIME |
TI. |
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.X=TIME TIME=100
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
TIME=<numeric> <n-var>=TIME
TIME$
Day.dd Mon yyyy,hh:mm:ss
Where:
The format is similar to that used on the Master Series BBC Micro except that the full-stop and comma are exchanged.
Day is the day of the week (Mon, Tue, etc). dd is the day of the month (01, 02, etc). Mon is the abbreviated month name (Jan, Feb ,etc). yyyy is the year (1986, 1987, etc). hh is hours (00 to 23). mm is minutes (00 to 59). ss is seconds (00 to 59).
The time, date or both time and date may be set as shown below.clock$=TIME$ TIME$="Sun.02 Feb 1986,18:33:30"
When setting the clock, the day of the week is ignored and may be omitted.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.
The first example below sets only the date and the second sets the date and the time.
No error is reported if the format is not accurately adhered to, however the clock may be set incorrectly.TIME$="02 Feb 1986" clock$="Mon.03 Feb 1986,22:31:15" TIME$=clock$
TIME$=<str> <s-var>=TIME$
TIME
For example,
will print10 FOR i=1 TO 5 STEP 1.5 20 PRINT i 30 NEXT 40 PRINT "**********" 50 PRINT i
Irrespective of the initial value of the loop control variable and the specified terminating value, the loop will execute at least once. For example,1 2.5 4 ********** 5.5
will print10 FOR i= 20 TO 10 20 PRINT i 30 NEXT
20
FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]
FOR, NEXT, STEP
The length of your program is given by TOP-PAGE.
PRINT TOP-PAGE
<n-var>=TOP
PAGE, HIMEM, LOMEM
TRACE |
TR. |
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,
would trace as10 FOR Z=0 TO 2:Q=Q*Z:NEXT 20 END
whereas[10] [20] >_
would trace as10 FOR Z=0 TO 2 20 Q=Q*Z:NEXT 30 END
and[10] [20] [20] [20] [30] >_
would trace as10 FOR Z=0 TO 3 20 Q=Q*Z 30 NEXT 40 END
[10] [20] [30] [20] [30] [20] [30] [40] >_
TRACE ON|OFF|<l-num> TRACE ON|OFF|(<numeric>)
None
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.10 flag=FALSE .... 100 IF answer$=correct$ flag=TRUE .... 150 IF flag PROC_got_it_right ELSE PROC_wrong
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.
<n-var>=TRUE
FALSE
UNTIL |
U. |
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.
Since the result of the test z=0 is ALWAYS FALSE, we can replace z=0 with FALSE. The program now becomes:10 z=1 20 REPEAT 30 INPUT "Enter a number " num 40 PRINT "The square of ";num;" is ";num*num 50 UNTIL z=0
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.20 REPEAT 30 INPUT "Enter a number " num 40 PRINT "The square of ";num;" is ";num*num 50 UNTIL FALSE
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.
UNTIL <t-cond>
REPEAT
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.
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.X=USR(lift_down)
<n-var>=USR(<numeric>)
CALL
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.X=VAL(A$)
For example,
would printPRINT VAL("-123.45.67ABC")
and-123.45
would printPRINT VAL("A+123.45")
VAL will NOT work with hexadecimal numbers. You must use EVAL to convert hexadecimal number strings.0
<n-var>=VAL(<str>)
STR$, EVAL
VDU |
V. |
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.
The bytes sent using the VDU statement do not contribute to the value of COUNT, but may well change POS and VPOS.VDU 8,8 :REM cursor left two places. VDU &0A0D;&0A0D; :REM CRLF twice
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.
VDU <numeric>{,|;<numeric>}[;]
CHR$
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.Y=VPOS
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
<n-var>=VPOS
POS
WIDTH |
W. |
If the specified width is zero (the initial value) the interpreter will not attempt to control the overall field width.WIDTH 80
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.
WIDTH <numeric>
COUNT
CONTENTS |
CONTINUE |