-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbasic.txt
5198 lines (4074 loc) · 178 KB
/
basic.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
BASIC V/VI Guide
~~~~~~~~~~~~~~~~
Contents
~~~~~~~~
Introduction
History
Features
Constants
Variables
Keywords
Line Numbers
Operators
Assignment Operators
Indirection Operators
Array Operations
Built-in Functions
Pseudo Variables
Procedures and Functions
Error Handling
Issuing Commands to the Underlying Operating System
Statement Types
Statements
Commands
The Program Environment
Screen Output
VDU Commands
PLOT Codes
Basic Keywords, Commands and Functions
Introduction
~~~~~~~~~~~~
The following notes give a brief introduction to BASIC V/VI and to
the environment that the interpreter emulates. They describe the
entire language but not in any great detail; more attention is
given to features specific to this version of Basic. Useful
information can be found on the web site 'The BBC Lives!' where
scanned version of manuals such as the 'BBC Microcomputer User
Guide' can be found. The information in these manuals is not 100%
relevant to BASIC V/VI but they are good for background information
and many details of BASIC II, the predecessor of (and to all
intents and purposes, a strict subset of) BASIC V/VI.
These notes describe the BASIC language. The file 'use' contains
information on how to use the interpreter and on the features
and limitations of the different versions of the program.
History
~~~~~~~
At the start of the 1980s the British Broadcasting Corporation was
looking for a microcomputer to be used for their series 'The
Computer Programme'. The machine chosen became known as the 'BBC
Micro' and it was made by Acorn Computers. It was an extremely
potent and flexible little computer that some people still use to
this day. The dialect of Basic on it was called 'BBC Basic'. This
was an extended Basic that added such features as procedures and
multi-line functions. It was also one of the fastest Basic
interpreters available on an eight-bit computer. The interpreter
was well integrated with the rest of the machine: it was possible
to directly call operating system functions from Basic programs
and there was also a built-in assembler. If something could not be
done in Basic or was too slow it was possible to write the code in
assembler. Many programs were written that used a combination of
Basic and assembler. Compilers and interpreters for languages such
as BCPL, C and Pascal were written for the BBC Micro, but by far
the most popular language was Basic.
In 1987 Acorn brought out the Archimedes. This included a new
version of the BBC Basic interpreter that had many additional
features such as 'CASE' statements and multi-line 'IF' statements.
It kept its reputation for speed. This version of Basic was called
'BASIC V', and later a version using 64-bit floating point numbers
was issued as a soft-load for RISC OS as 'BASIC VI' and it is the
dialect of the language implemented by this interpreter.
The operating system that ran on the Archimedes and the machines
that have succeeded it over the years is called 'RISC OS'. This
was designed and written by Acorn Computers.
Features
~~~~~~~~
The main features of BASIC V/VI are:
1) It is a structured Basic with a full range of statement
types such as WHILE and REPEAT loops, a block IF statement
and a CASE statement.
2) It has procedures and multi-line functions which can have
local variables and arrays.
3) It has 'indirection operators' which allow data structures to
be constructed and manipulated. Memory can be allocated from
the Basic heap that can be referenced using these operators.
(This is not to say that the dialect includes data structures
per se but they can be set up and used in a way that appears
to be reminiscent of BCPL.)
4) The Acorn-written interpreters include an assembler.
Programs can be written using a mix of Basic and assembler.
All the features of the Basic interpreter are available to
the assembler, so that, for example, functions written in
Basic are used as macros.
5) Speed: the interpreter is very fast.
Notation
~~~~~~~~
A few words on the notation used in these notes might be in
order.
In describing the syntax of statements, parts of the statement
are often put in angle brackets <like this>. The purpose of
this is to say what goes at that part of the statement, for
example:
GOSUB <line number>
This says that the keyword GOSUB is to be followed by a line
number if a GOSUB statement is used in the program. Another
example:
ON ERROR <statements>
This one says that in an 'ON ERROR' statement, the keywords
'ON ERROR' are followed by one or more Basic statements.
In some cases, parts of a statement are in square brackets,
for example:
IF <expression> THEN <line number>
[ ELSE <line number> ]
This means that that part of the statement is optional. In
the example, the '[ ELSE <line number> ]' part of the
statement can be omitted.
Constants
~~~~~~~~~
The interpreter supports five types of variable:
- Decimal integer
- Hexadecimal integer
- Binary integer
- Floating point
- String
Hexadecimal constants begin with a '&' and binary ones with a '%'.
Strings are enclosed in '"'. It is possible to embed a '"' is a
string by preceding it with another '"'. Examples:
&FFFF
&123456
%1001101
%1
"abcdefghij"
"klmnop""qrst"
Variables
~~~~~~~~~
The interpreter supports three main types:
32-bit integer e.g. abc%
64-bit integer e.g. def%%
Floating point e.g. ghi
String e.g. jkl$
32-bit integer variables are denoted as being a 32-bit
integer by having a '%' at the end of the name.
64-bit integer variables are denoted as being a 64-bit
integer by having a double '%%' at the end of the name.
Floating point variables are 64 bits wide. If a variable does
not have either a '%', '%%' or a '$' suffix then it is a floating
point variable.
String variables have a '$' suffix at the end of their name. They
can refer to strings that have a maximum length of 65,536
characters.
Note that it is possible for variables of different types to have
the same name, for example, 'abc%', 'abc' and 'abc$' can all exist
at the same time. The '%' and '$' are considered to be part of the
name. Similarly, it is possible to have arrays and simple
variables of the same name, for example:
abcd$ <-- String variable
abcd$() <-- String array
What happens is that the '(' is considered to be part of the name
of the array.
Variable names are case sensitive, so that 'abcd' and 'AbCd' are
different variables.
BASIC V/VI has two classes of variables, the normal dynamic variables
that are created when the program runs and a set of what are
called 'static' variables which comprises of the integer variables
A% to Z%. These variables are independent of any program in that
their valaues are not reset or changed when a program is loaded or
modified. They can, for example, be used to pass values from
one program to another.
Keywords
~~~~~~~~
Keywords are Basic's reserved words. They are split into two types
in this interpreter, Basic keywords and Basic commands. Examples
of the former are 'IF', 'ENDPROC' and 'WHILE'. Examples of
commands are 'LOAD', 'LIST' and 'NEW'. A complete list of keywords
is given at the end of these notes.
If Matrix Brandy is compiled with -DBRANDY_ALLOW_LOWERCASE_COMMANDS,
Basic keywords have to be in upper case. On the other hand,
commands can be given in either lower or upper case to make it
more convenient to type them in. Otherwise all commands must
be entered in upper case, as is the case with the BBC Micro and
RISC OS versions of BBC BASIC.
The interpreter tries to be clever with keywords. In general
keywords cannot be used as variable names but there are cases
where if a keyword is followed by a letter it is not identified as
a keyword, for example, 'COUNT' on its own is a keyword but
'COUNTER' can be used as a variable without any problems. The
keywords taht can are treated in this way are marked with a '*'
in the keyword list at the end of the notes.
Line Numbers
~~~~~~~~~~~~
Each line in a Basic program has a line number. This is used when
editing a program at the command line and in the program by such
statements as 'GOTO', 'GOSUB', 'ON GOTO', and 'RESTORE'. BASIC V/VI
is a structured Basic and line numbers are largely superfluous if
statement types such as these are not used. They are still needed
to identify the line on which an error was detected when a program
runs. Programs and libraries can be written without line numbers
using a text editor such as 'vi'. Line numbers will automatically
be added when the program is loaded. Similarly, programs can be
saved without line numbers, although the default is to include
them.
Line numbers are in the range 0 to 65279.
Operators
~~~~~~~~~
BASIC V/VI supports the usual range of operators. The following list
details what is available. The operators are given in priority
order, with operators of the same priority grouped together. From
highest to lowest priority they are:
^ Exponentiation
------------------
* Multiplication
/ Division
DIV Integer division
MOD Integer modulus
------------------
+ Addition and string concatenation
- Subtraction
------------------
= Equals
<> Not equals
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<< Left shift
>> Arithmetic right shift
>>> Logical right shift
------------------
AND Logical AND
------------------
OR Logical OR
EOR Exclusive OR
There is a point to watch out for when using the comparison and
shift operators. It is not possible to chain these together in an
expression, for example:
abc% >> 2 <= 10
will give an error. The solution is to put brackets around the
first part of the expression thus:
(abc% >> 2) <= 10
This is a feature of BASIC V/VI.
Assignment Operators
~~~~~~~~~~~~~~~~~~~~
As well as using '=' for assignments in the normal way, BASIC V/VI
has two other assignment operators:
<variable> += <expression>
<variable> -= <expression>
'+=' adds <expression> to the variable <variable> and '-='
subtracts it.
Examples:
abc% += 1
ghi(N%) -= count
xyz$ += "abcd"
table%!offset% -= X%
$(table%+name%) += "xyz"
Matrix Brandy offers 5 more from BB4W and BBCSDL, and JGH's ARM BBC BASIC Plus.
These are:
<variable> AND= <expression>
<variable> OR= <expression>
<variable> EOR= <expression>
<variable> MOD= <expression>
<variable> DIV= <expression>
Examples:
a% AND=&7F
a OR=128
These five all operate on integers, and where float values are supplied
will be truncated to integers. Of the eight assignment operators,
only = and += are valid for string types.
Indirection Operators
~~~~~~~~~~~~~~~~~~~~~
These are equivalent to 'peek' and 'poke' in other versions of
Basic except that they are far more flexible and powerful.
Strictly speaking these are not proper operators but language
constructs.
There are two types of operator, unary and dyadic. The unary ones
are:
? Reference to a one byte integer
! Reference to a four byte integer
| Reference to a floating point value
] Reference to an eight byte integer
$ Reference to a string
The dyadic operators are:
? Reference to a one byte integer
! Reference to a four byte integer
Note that there are not dyadic versions of '$', ']' and '|'.
Unary operators can be followed by a variable, array reference or
an expression in parentheses. For dyadic operators, the item
before the operator must be a variable or array reference. A
variable, array reference or expression in parentheses follows the
operator.
Examples of unary operators:
$pointer%
!abc%
?(abc%+10)
](abc%%+40)=8589934592
$text% = "abc"
Examples of dyadic operators:
pointer%!offset%
abc%?next%
array%(N%)!field%
The operators all work in the same way. The value of the
expression after the operator (unary version) or of the variable
before the operator (dyadic version) is interpreted as an address.
The value after the operator in the dyadic version is a byte
offset from that address.
Indirection operators cannot be chained together, that is, they
cannot be used in an expression such as:
pointer%!offset%!field%
In general, indirection operators can be used in the same way and
places as normal variables and the two forms of reference can be
freely mixed.
Examples:
IF $text%="quit" THEN STOP
table%!offset% = table%!offset2
!(table%+offset%) = !(table%+offset2)
abc = |address+1.0
PROCabcd(!table%, table%!4)
FOR table%!8=1 TO 10: NEXT
The interpreter limits the range of addresses that can be read
from or written to using indirection operators to the Basic
workspace. It is not possible to access any location outside this
block of memory.
Indirection operators can be used to built up and manipulate data
structures. However they are not true data structures in the sense
of structs in a C program and there are no checks on the legality
of references (beyond ensuring that the addresses are in range).
It is possible for a program to allocate memory from the Basic
heap to be used used for data structures and accessed via the
indirection operators. A special form of the DIM statement is
used for this:
DIM table%% 100
Strictly speaking this allocates a byte array with indexes 0 to
100. From a more practical point of view, it allocates a 101 byte
block of memory and puts its address in table%. This block can
then be manipulated using the indirection operators as desired,
for example:
$table%%="an error message"
table%%!0 = 0: table%%!4 = 99
In fact, blocks of memory allocated this way can only be
referenced via indirection operators.
Similarly, memory outside the heap can be requested using DIM HIMEM
(a Basalt extension). This memory can also be freed using
DIM HIMEM var%% -1. Memory allocated this way, like that allocated
from the heap using a regular DIM, can only be referenced via indirection
operators.
Numeric arrays can also be defined off-heap using DIM HIMEM, but these
use a different syntax to free them, see CLEAR HIMEM.
Note that it is recommended to use a 64-bit integer when DIMming memory,
as on a 64-bit system there is no guarantee you will be allocated memory
in the bottom 4GB of the memory map.
A word of warning: If this is used in conjunction with LOCAL, the array or
memory block must be deallocated before exiting the procedure, otherwise
your program will cause a memory leak.
Array Operations
~~~~~~~~~~~~~~~~
The interpreter supports some arithmetic operations on entire
arrays. There are some restrictions: the arrays have to be the
same size (number of dimensions and size of each dimension) and of
exactly the same type. Also, general expressions involving arrays
are not allowed, nor is it possible to return an array as the
result from a function. What is allowed is as follows:
Assignment
----------
<array 1> = <array 2>
The contents of <array 2> are copied to <array 1>
<array> = <expression>
All elements of array <array> are set to <expression>
<array> = <expression 1> , <expression 2> , ... , <expression n>
Each expression <expression x> is evaluated and then assigned
to the x'th element of the array <array>. There can be fewer
expressions than there are elements in the array, in which case
the remaining array elements are left unchanged.
<array 1> += <array 2>, <array 1> -= <array2>
Each element of <array 2> is added to <subtracted from) the
corresponding element in <array 1>.
<array> += <expression>, <array> -= <expression>
The expression <expression> is evaluated and the result added
to <subtracted from) each element of <array>.
Examples:
abc%() = def%()
ghi$() = "test"
jkl() = 0.0, 1.1, 2.2, 3.3, FNxyz(4.4)
abc%() += def%()
jhl() -= PI
Addition and Subtraction
------------------------
<array 1> = <array 2> + <array 3>
Add the corresponding elements of <array 2> and <array 3> and
store the result in the same element in <array 1>.
<array 1> = <array 2> - <array 3>
Subtract the elements in <array 3> from the corresponding element
in array <2> and store the result in <array 1>.
<array 1> = <array 2> + <expression>
<array 1> = <expression> + <array 2>
Add <expression> to each element of <array 2>, storing the result
of each addition in the corresponding element of <array 1>.
<array 1> = <array 2> - <expression>
<array 1> = <expression> - <array 2>
Subtract <expression> from each element of <array 2>, storing the
result of each subtraction in the corresponding element of
<array 1>.
Examples:
abc%() = def%() + ghi%()
jkl() = mno() - pqr()
aaa$() = bbb$() + "ccc" + FNddd(eee$)
abc%() = 1 - def%()
Multiplication and Division
---------------------------
<array 1> = <array 2> * <array 3>
Multiply each element of <array 2> by the corresponding element
in <array 3> and store the result in <array 1>.
<array 1> = <array 2> / <array 3>
Divide each element of <array 2> by the corresponding element
in <array 3> and store the result in <array 1>.
<array 1> = <array 2> DIV <array 3>
Carry out an integer division of each element of <array 2> by the
corresponding element in <array 3> and store the result in
<array 1>.
<array 1> = <array 2> MOD <array 3>
Carry out an integer division of each element of <array 2> by the
corresponding element in <array 3> and store the remainder in
<array 1>.
<array 1> = <array 2> * <expression>
<array 1> = <expression> * <array 2>
Multiply each element of <array 2> by the value <expression> and
store the result in the corresponding element in <array 1>.
<array 1> = <array 2> / <expression>
Divide each element of <array 2> by the value <expression> and
store the result in the corresponding element in <array 1>.
<array 1> = <expression> / <array 2>
Divide <expression> by each element of <array 2> and store the
result in the corresponding element in <array 1>.
<array 1> = <array 2> DIV <expression>
Carry out an integer division of each element of <array 2> by the
value <expression> and store the result in the corresponding
element in <array 1>.
<array 1> = <expression> DIV <array 2>
Carry out an integer division of <expression> by each element of
<array 2> and store the result in the corresponding element in
<array 1>.
<array 1> = <array 2> MOD <expression>
Carry out an integer division of each element of <array 2> by the
value <expression> and store the remainder in the corresponding
element in <array 1>.
<array 1> = <expression> MOD <array 2>
Carry out an integer division of <expression> by each element of
<array 2> and store the remainder in the corresponding element in
<array 1>.
Examples:
abc() = def() * ghi()
abc() = 10.0 * ghi()
jkl%() = mno%() MOD 100
abc() = 1 / abc()
Matrix Multiplication
---------------------
<array 1> = <array 2> . <array 3>
Perform a matrix multiplication of <array 2> and <array 3> and
store the result in <array 1>.
Note that '.' is used as the matrix multiplication operator.
Built-in Functions
~~~~~~~~~~~~~~~~~~
The interpreter has a fairly standard set of functions. One
feature of this dialect of Basic is that many of the functions
look like monadic operators, for example, a call to the 'LEN'
function can be written as 'LEN abc$' as well as 'LEN(abc$)'.
Function names can often be abbreviated when typing them at the
command line. The abbreviated version of the name is the first
few characters of the name followed by a dot, for example, the
'LE' is the abbreviated form of 'LEFT$('. The names are given
in full when the program is listed.
Following is a list of functions implemented and a summary of
their actions. More detailed information on the vast majority of
them can be found in the manuals on the 'The BBC Lives!' web site.
Entries marked with a '*' after the name are functions added in
this interpreter.
<factor> represents a simple expression that consists of just a
variable name, array reference or constant or a complete
expression in parentheses.
<expression> is a full expression. Sometimes this is written as
<string expression> or <numeric expression> to qualify the type
of expression, or abbreviated to <expr> to reduce clutter.
<array> is a reference to a whole array.
ABS
Use: ABS <factor>
Returns the absolute value of the numeric value
<factor>
ACS
Use: ACS <factor>
Returns the arccosine of the numeric value <factor>
ADVAL
Use: ADVAL <factor>
This is an unsupported function. Either use of it is
flagged as an error or it returns zero, depending on the
options used to start the interpreter.
ARGC *
Use: ARGC
Returns the number of parameters on the command line.
This will be zero if there are no parameters.
ARGV$ *
Use: ARGV$ <factor>
Returns parameter number <factor> on the command line
as a string. ARGV$ 0 returns the name of the program.
ARGV$ 1 is the first parameter, ARGV$ 2 the second and
so forth. ARGV$ ARGC is the last parameter.
ASN
Use: ASN <factor>
Returns the arcsine of the numeric value <factor>
ATN
Use: ATN <factor>
Use: ATN(y,x)
In the first form, this returns the arctan of the numeric
value <factor>.
In the second form, this calculates the principal value
of the arc tangent of (y/x), using the signs of the two
arguments to determine the quadrant of the result.
BEAT
Use: BEAT
Returns information from the RISC OS sound system.
BGET
Use: BGET# <factor>
Returns the next byte from the file with handle <factor>
CHR$
Use: CHR$ <factor>
Returns a string consisting of a single character with
ASCII code <factor>
COLOUR
Use: COLOUR(<red expression>, <green expression>,
<blue expression>)
This takes the colour with the specified colour
components and returns a number that represents the
closest match to that colour in the current screen
mode. This value is for use with the 'COLOUR OF' and
'GCOL OF' statements. It has no meaning otherwise.
Example:
red = COLOUR(255, 0, 0): COLOUR OF red
COS
Use: COS <factor>
Returns the cosine of the numeric value <factor>
COUNT
Use: COUNT
Returns the number of characters printed on the current
line by PRINT.
DEG
Use: DEG <factor>
Converts the angle <factor> from radians to degrees.
DIM
Use: a) DIM(<array>)
b) DIM(<array>, <expression>)
a) returns the number of dimensions in array <array>.
b) returns the highest index of dimemsion <expression> of
array <array>.
END
Use: END
Returns the address of the top of the Basic heap.
EOF
Use: EOF# <factor>
Returns TRUE if the file with handle <factor> is at end of
file.
ERL
Use: ERL
Returns the number of the line that contained the last error
encountered by the interpreter or zero if no error has been
seen.
ERR
Use: ERR
Returns the error number of the last error encountered by
the interpreter or zero.
EVAL
Use: EVAL <factor>
Evaluates the string <factor> as if it were an expression in
a statement in the program and returns the result.
EXP
Use: EXP <factor>
Returns the exponentional of the numeric value <factor>.
FALSE
Use: FALSE
The function returns the value corresponding to 'false' in
the interpreter (zero).
GET
Use: a) GET
b) GET(x,y)
a) Returns the next character pressed on the keyboard as a
number, waiting if there is not one available.
b) Returns the character at position (x,y) on the screen.
This only works on the SDL build; on text builds this returns 0.
GET$
Use: a) GET$
b) GET$# <factor>
c) GET$(x,y)
a) Returns the next character pressed on the keyboard as a
one character string, waiting if there is not one
available.
b) Returns the next line from the open file with handle
<factor> as a character string.
c) Returns the character at position (x,y) on the screen.
This only works on the SDL build; on text builds this returns 0.
INKEY
Use: INKEY <factor>
If numeric value <factor> is greater than or equal to zero,
return the next character pressed on the keyboard as a number
but only wait for <factor> centiseconds. Return -1 if no key
pressed in that time.
If numeric value <factor> is -256, return a number that
identifies the operating system under which the program is
running. (See the 'use' guide for the values returned.)
If numeric factor <factor> is less than zero and greater
than -256, return TRUE if the key with RISC OS internal
key number <factor> is being pressed otherwise return FALSE.
INKEY$
Use: INKEY$ <factor>
This is the same as INKEY but returns its result as a single
character string. In the case of a keyboard read with
timeout, an empty string is returned if the time limit
expires instead of -1.
INSTR(
Use: INSTR(<expr1> , <expr2> [, <expr3>])
Search string <expr1> for the string <expr2> returning the
index (starting from 1) of the start of <expr2> in <expr1>
if the string is found otherwise return zero. <expr3> is
an option expression that gives a starting point in <expr1>
at which to start looking for <expr2>.
INT
Use: INT <factor>
Returns the integer part of number <factor>, rounding down
(towards minus infinity). By default (matching 6502, 32000,
PDP11 and ARM BASIC) the value must be within the range
-2^31 to 2^31-1 that can be stored within an integer variable.
However, to allow values out of this range (so INT actually
returns a floating-point value) do: SYS "Brandy_INTusesFloat",1
LEN
Use: LEN <factor>
Returns the length of string <factor>.
LISTO *
Use: LISTO
Returns the current LISTO setting.
LN
Use: LN <factor>
Return the natural log of number <factor>.
LOG
Use: LOG <factor>
Returns the base 10 log of number <factor>.
MOD Use: MOD <array>
Returns the modulus (square root of the sum of the
squares) of numeric array <array>.
MODE Use: MODE
Returns the number of the current RISC OS screen mode.
NOT
Use: NOT <factor>
Returns the logical negation (ones complement) of numeric
value <factor>.
OPENIN
Use: OPENIN <factor>
Opens the file named by the string <factor> for input and
returns its numeric handle or zero if it cannot be opened.
OPENOUT
Use: OPENOUT <factor>
Opens the file named by the string <factor> for output and
returns its numeric handle. If the file exists already its
length is reset to zero.
OPENUP
Use: OPENUP <factor>
Opens the file named by the string <factor> for both input
and output and returns its numeric handle.
Network sockets can also be opened, see docs/networking.txt.
PI
Use: PI
Returns the value PI.
POINT(
Use: POINT(<x expr>,<y expr>)
Returns the colour number of the point on the graphics
screen with graphics coordinates (<x expr>, <y expr>).
POS
Use: POS
Returns the offset (from 0) of the text cursor from
the left-hand side of the screen.
QUIT
Use: QUIT
Returns TRUE if the interpreter was started with the
option '-quit', that is, the interpreter will be exited
from when the Basic program finishes running.
RAD
Use: RAD <factor>
Convert the angle <factor> given in degrees to radians.
REPORT$
Use: REPORT$
Returns the message for the last error encountered.
RND
Use: a) RND
b) RND(<negative expr>)
c) RND(0)
d) RND(1)
e) RND(<expression>)
a) Return a pseudo-random number in the range -2147483648
to 2147483647
b) Initialises the random number generator with seed value
<negative expr>.
c) Returns the last number generated by RND(1).
d) Returns a floating point number in the range 0 to 1.
e) Returns an integer number in the range 1 to <expression>.
SGN
Use: SGN <factor>
Returns -1 if the numeric value <factor> is less than
zero, zero if it is zero or 1 if it is greater than zero.
SIN
Use: SIN <factor>
Returns the sine of numeric value <factor>.
SQR
Use: SQR <factor>
Returns the square root of numeric value <factor>.
STR
Use: a) STR <factor>
b) STR~ <factor>
a) Converts the numeric value <factor> to a decimal
string.
b) Converts the numeric value <factor> to a hexadecimal
string.
STRING$(
Use: STRING$( <expression>, <string expr> )
Returns a string made from the string <string expr> repeated
<expression> times.
SUM
Use: SUM <array>
If <array> is a numeric array it returns the sum of all of
the elements of the array. If <array> is a string array it
returns a string made from all of the elements of <array>
concatenated.
SUM LEN
Use: SUM LEN <array>
Returns the total length of all of the strings in string
array <array>.
SYS(
Use: SYS(<string>)
This is a wrapper for SYS call OS_SWINumberFromString, and
returns the SWI number for a given SWI name.
TAN
Use: TAN <factor>
Returns the tangent of numeric value <factor>
TEMPO
Use: TEMPO
Unsupported RISC OS feature. The function returns zero or
generates an error depending on intepreter command line
options.
TINT
Use: TINT(<x expr>,<y expr>)
Returns the TINT value of the position with x and y
graphics coordinates <x expr> and <y expr> on the screen
in 256 colour modes.
TOP
Use: TOP
Returns the address of the first byte after the Basic
program.
TRACE
Use: TRACE
Returns the handle of the file to which TRACE output is
being written or zero if a file is not being used.
TRUE
Use: TRUE
Returns the value used by the interpreter for 'true' (-1).
USR
Use: USR <factor>
Calls machine code at address <factor>. Not implemented
this interpreter except in one special case. See the
'use' guide.
VAL
Use: VAL <factor>
Converts the string <factor> to a number.
VERIFY( *
Use: VERIFY(<expr 1>, <expr 2> [, <expr 3>] )
Returns the offset of the first character in string
expression <expr 1> that is not in string <expr 2>
or zero if all characters in <expr 1> are in <expr 2>.
<expr 3> is the optional position at which to start
the search.
VDU
Use: VDU <factor>
Returns the value of the RISC OS mode variable given by
<factor>. This can be used to determine such things as
the screen width, the number of colours and so forth.
Refer to the section 'Mode Variables' below for more
details.
VPOS
Use: VPOS
Returns the offset (from zero) from the top of the screen of
the text cursor.
WIDTH
Use: WIDTH
The function returns the current value of 'WIDTH' (the
width of the current line as set by the program) or zero
if a line width has not been defined via the WIDTH
statement.
XLATE$( *
Use: a) XLATE$(<expr 1>)
b) XLATE$(<expr 1>, <expr 2>)
a) Returns the string expression <expr 1> with all
upper case characters converted to lower case.
b) Returns the string expression <expr 1> with the
characters translated using string expression or
string array <expr 2>. Characters in <expr 1> are
replaced with the character in the position
corresponding to the ASCII code of the original
character.
Pseudo Variables
~~~~~~~~~~~~~~~~
Pseudo variables are a half way house between a function and a
variable. When they appear in the right hand side of an expression
they are functions but they can also appear on the left hand side of
an expression too.
Pseudo variables cannot follow the keyword 'LET', that is, using
them in statements such as: