-
-
Couldn't load subscription status.
- Fork 8
Language reference
- Metasyntax
- Definitions
- Literals
- Variables
- Operators
- Functions
-
Statements
- BEEP, BLOAD, BSAVE, CALL, CHDIR, CIRCLE, CLEAR, CLOSE, CLS, COLOR, CONT, COPY, DATA, DEF FN, DELETE, DIM, DOKE, DRAW, EDIT, ELSE, END, ERROR, FILES, FOR, GOSUB, GOTO, IF, INPUT, KEY, KILL, LET, LINE, LIST, LOAD, LOCATE, MERGE, MKDIR, NAME, NEW, NEXT, OLD, ON, ON ERROR, OPEN, OUT, PALETTE, PLAY, PLOT, POKE, PRINT, RANDOMIZE, READ, REM, RENUM, RMDIR, RUN, SAVE, SCREEN, SEEK, SOUND, STOP, TRACE, WAIT, WEND, WHILE
- Errors and messages
This documentation describes the SE Basic IV language. Differences with Microsoft BASIC do arise, and where this is the case they are documented.
Note that Microsoft's official documentation is rather hit-and-miss; it leaves several features undocumented and incorrectly describes others. To avoid making the same errors, the present documentation was written from scratch with reference to the actual behavior. The errors in this document are therefore all our own. Contact us if you encounter them.
In descriptions of BASIC syntax, the following conventions apply. Exact rendering of the markup may vary depending on the means used to display this documentation.
bold: Type exactly as shown.
italic: Replace with appropriate metavariable.
[a]: Entities within square brackets are optional.
{ a | b }: Disjunct alternatives of which one must be chosen.
[ a | b ]: Optional disjunct alternatives.
a ...: Preceding entity can be repeated.
A program line consists of a line number followed by a compound statement. Program lines are terminated by a CR or by the end of the file.
A line number is a whole number in the range [1 to 16383]. Note that Microsoft BASIC supports line numbers in the range [0 to 65529].
A compound statement consists of statements separated by colons:
statement [: statement] ...
An expression takes one of the following forms:
unary_operator{literal|variable|array_element|function}
expression binary_operator expression
(expression)
whose elements are described the sections Literals, Variables, Operators and Functions.
An array element takes the form:
array{[|(}numeric_expression[,numeric_expression] ... {)|]}
String literals are of the following form:
"[characters]"
where characters is a string of characters. Any character from the current code page can be used.
String literals should not contain any of the characters in the ASCII range $00—$1F, which lead to unpredictable results. There is no escaping mechanism. To include one of the above characters in a string, use [string concatenation](#string concatenation) and the CHR$ function.
Numeric literals have one of the following forms:
[+|-] [0|1|2|3|4|5|6|7|8|9]... [.][0|1|2|3|4|5|6|7|8|9]... [{E|e|}
$[0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|a|b|c|d|e|f]...
@[0|1|2|3|4|5|6|7]...
%[0|1]...
Literals may contain spaces.
Hexadecimal, octal and binary literals denote positive integers and do not include a sign. They must range between [$0 to $ffff]. This is in contrast to Microsoft BASIC where the range [$8000 to $ffff] is interpreted as a two's complement negative integer; for example, $FFFF = -1.
Floating-point literals must be specified in decimal notation. The decimal separator is the point. A base-10 exponent may be specified after E.
Examples of valid numeric literals are -1 42 1.3523523 .235435 -.3 3. 1.1e+7 1e2 1e-2 @7 $ffff @20 $ @ % 65537 1.1
Note that expressions such as @-77 are legal; these are however not negative octals but rather the expression @ (empty octal; zero) less 77 (decimal 77).
Variable names must start with a letter; all characters of the variable name (except the $) must be letters A to Z or figures 0 to 9. A dot (.) is not permitted. All characters in the name are significant. A variable name must not be identical to a reserved word or a reserved word plus '$'. Therefore, for example, you cannot name a variable TO$ but you can name it AS$. Variable names may contain any reserved word. Variable names may also start with a reserved word. Thus COST and LUSR$ are legal variable names.
For each name, two different variables may exist corresponding to the two types. That is, you can have A$ and A as different variables.
Currently, the array A() is separate from the scalar variables of the same name but the array A$() is not. Unlike Microsoft BASIC, the latter is a character array.
SE Basic IV recognizes three variable types. Strings are indicated with a $ suffix. Whole numbers in the range -65536 to 65535 are stored as integers. All other numbers are stored as extended-precision floating-point numbers precise to ~9 significant figures.
Arrays are indexed with round brackes. Multidimensional arrays are specified by separating the indeces with commas: A(0, 0), A(0, 0, 0), and so on.
By default, arrays are indexed from 1. In Microsoft BASIC arrays are indexed from 0, but this can be changed using OPTION BASE 1.
Arrays can be allocated by specifying the largets allowed index using DIM. Unlike Microsoft BASIC, if all indeces of the array are 10 or less, they must be explicitly allocated. Also, it is not necessary to perform any actions beofre re-allocating an array.
Multi-dimensional arrays are stored in column-major order, such that A(2, 0) immediately follows A(1,0).
The order of precedence of operators is as follows, from tightly bound (high precedence) to loosely bound (low precedence):
10. ^
9. * /
8. \
7. MOD
6. + - (unary and binary)
5. = <> < > <= >=
4. NOT (unary)
3. AND
2. OR
1. XOR
Unlike Microsoft BASIC, EQV and IMP are not currently supported. SE Basic IV converts the alternates for not equal (><), greater than or equal (=<) or less than or equal (=>) to standard notation.
Expressions within parentheses () are evaluated first. All binary operators are left-associative: operators of equal precedence are evaluated left to right.
- Exponentiation is more tightly bound than negation:
-1^2 = -(1^2) = -1but(-1)^2 = 1. - Exponentiation is left-associative:
2^3^4 = (2^3)^4 = 4096.
- If any operator other than
+,-orNOTis used without a left operand, an error is raised. - At the end of a statement, if any operator is used without a right operand, an error is raised. If this occurs elsewhere inside a statement, such as within brackets, an error is raised.
Mathematical operators operate on numeric expressions only. Note however that + can take the role of the string concatenation operator if both operands are strings.
| Code | Operation | Result |
|---|---|---|
x ^ y |
Exponentiation |
x raised to the power of y
|
x * y |
Multiplication | Product of x and y
|
x / y |
Division | Quotient of x and y
|
x \ y |
Truncated division | Integer quotient of x and y
|
x MOD y |
Modulo | Integer remainder of x by y (with the sign of x) |
x + y |
Addition | Sum of x and y
|
x - y |
Subtraction | Difference of x and y
|
+ y |
Unary Plus | Value of y
|
- y |
Negation | Negative value of y
|
The expression 0^0 will return 1 and not raise an error, even though, mathematically, raising zero to the zeroeth power is undefined.
- If either operand is a string, an error will be raised. The exception is
+which will only raise Type mismatch if either but not both operands are strings. - If
y=0,x / y,x MOD yandx \ ywill raise an error. - If
x=0andy<0,x^ywill raise an error. - If the result of any operation is too large to fit in a floating-point data type, an error is raised.
- If operands or result of
\orMODare not in[-32768 to 32767], an error is raised.
| Code | Operation | Result |
|---|---|---|
x$ + y$ |
Concatenation | The contents of x$ followed by the contents of y$
|
x$ * y |
Repetition | The contents of x$ is repeated y times. If y is negative, the result is mirrored. |
x$ AND y |
Selection | If y is zero, the result is an empty string, otherwise x$
|
Relational operators can operate on numeric as well as string operands; however, if one operand is string and the other numeric, an error is raised.
Relational operators return either 0 (for false) or -1 for true.
| Code | Operation | Result |
|---|---|---|
= |
Equal | True if a equals b, false otherwise. |
<> (><) |
Not equal | False if a equals b, true otherwise. |
< |
Less than | True if a is less than b, false otherwise. |
> |
Greater than | True if a is greater than b, false otherwise. |
<= (=<) |
Less than or equal | False if a is greater than b, true otherwise. |
>= (=>) |
Greater than or equal | False if a is less than b, true otherwise. |
When operating on numeric operands, both operands are compared as floating-point numbers according to the usual ordering of numbers. The equals operator tests for equality to within machine precision for the highest-precision of the two operator types.
When comparing strings, the ordering is as follows.
- Two strings are equal only if they are of the same length and every character code of the first string agrees with the corresponding character code of the second. This includes any whitespace or unprintable characters.
- Each character position of the strings is compared starting with the leftmost character. When a pair of different characters is encountered, the string with the character of lesser code point is less than the string with the character of greater code point.
- If the strings are of different length, but equal up to the length of the shorter string, then the shorter string is less than the longer string.
Note: the tokenizer converts the symbols ><, => and =< to <>, >= and <= respectively.
SE Basic IV has no Boolean type and does not implement Boolean operators. It does, however, implement bitwise operators. In direct mode, SE Basic IV enables characters to be used as a subsitute for typing the operator name.
| Character | Code |
|---|---|
~ |
NOT |
& |
AND |
| |
OR |
Bitwise operators operate on numeric expressions only. Floating-point operands are rounded to integers before being used.
| Code | Operation | Result |
|---|---|---|
NOT y |
Complement | -y-1 |
x AND y |
Bitwise conjunction | The bitwise AND of x and y
|
x OR y |
Bitwise disjunction | The bitwise OR of x and y
|
x XOR y |
Bitwise exclusive or | The bitwise XOR of x and y
|
These operators can be used as Boolean operators only if -1 is used to represent true while 0 represents false. Note that SE Basic IV represents negative integers using the two's complement, so NOT 0 = -1. The Boolean interpretation of bitwise operators is given in the table below.
Code|Operation|Result
NOT y|Logical negation|True if y is false and vice versa
x AND y|Conjunction|Only true if both x and y are true
x OR y|Disjunction|Only false if both x and y are false
x XOR y|Exclusive or|True if the truth values of x and y differ
Be aware that when used on integers other than 0 and -1, bitwise operators can not be interpreted as Boolean operators. For example, 2 AND 1 returns 0.
If either (but not both) operands to a concatenation are numeric, an error will be raised.
Functions can only be used as part of an expression within a statement; they may take input values between parentheses and produce a return value. For example, in PRINT ABS(-1) the ABS function is used in an expression within a PRINT statement; in Y = SQR(X) + 2 the SQR function is used in an expression within a LET statement.
Some reference works also use terms such as system variable for functions that do not take an input, presumably since in the Microsoft BASIC syntax such functions have no parentheses, in contrast to the languages in the C family (and indeed some modern BASICs). However, this is simply the Microsoft BASIC syntax for functions without inputs. For example, one can do DEF FN A=1: PRINT FN A in which no parentheses are allowed.
In Microsoft BASIC, the input of a function must be contained in parentheses. In SE Basic IV the parentheses are usually optional.
y = ABS(x)
Returns the absolute value of x if x is a number and the value of x if x is a string.
x is an expression.
y = ACOS(x)
Returns the inverse cosine of x.
x is a numeric expression that gives the angle in radians.
x has a string value: Type mismatch.
val = ASC(char)
Returns the code point (ASCII value) for the first character of char.
char is an expression with a string value.
-
charhas a numeric value: Type mismatch. -
charequals"": Illegal function call.
y = ASIN(x)
Returns the inverse sine of x.
x is a numeric expression that gives the angle in radians.
x has a string value: Type mismatch.
y = ATAN(x)
Returns the inverse tangent of x.
x is a numeric expression that gives the angle in radians.
x has a string value: Type mismatch.
char = CHR$(x)
Returns the character with code point x.
x is a numeric expression in the range [0 to 255].
-
xhas a string value: Type mismatch. -
xis not in[-32768 to 32767]: Overflow. -
xis not in0 to 255: Illegal function call.
cosine = COS(angle)
Returns the cosine of angle.
angle is a numeric expression that gives the angle in radians.
angle has a string value: Type mismatch.
value = DEEK(address)
Returns the 16-bit value of the memory at segment * 16 + address where segment
is the current segment set with DEF SEG.
address is a numeric expression in [-32768 to 65535]. Negative values are interpreted as their two's complement.
y = EXP(x)
Returns the exponential of x, that is e to the power x.
x is a number- valued expression.
-
xhas a string value: Type mismatch. -
xis larger than the natural logarithm of the maximum single-precision value: Overflow.
whole = FIX(number)
Returns a number truncated towards zero.
number is a numeric expression.
FIX truncates towards zero: it removes the fractional part. By contrast, INT truncates towards negative infinity.
-
numberis a string expression: Type mismatch.
result = FN[ ]name [(arg_0 [, arg_1] ...)
Evaluates the user-defined function previously defined with DEF FN name. Spaces between FN and name are required.
-
nameis the name of a previously defined function. -
arg_0, arg_1, ...are expressions, given as parameters to the function.
- In Microsoft BASIC, spaces between
FNandnameare optional. - Unlike Microsoft BASIC, in SE Basic IV, functions can be called recursively, albeit without tail call optimization.
- No function named
nameis defined: Undefined user function. - The number of parameters differs from the function definition: Syntax error.
- The type of one or more parameters differs from the function definition: Type mismatch.
- The return type is incompatible with the function name's sigil: Type mismatch.
key = INKEY$ [ #file_num]
Returns one character from the stream file_num. If no stream is specified, returns one key-press from the keyboard buffer. If the keyboard buffer is empty, returns the empty string. Otherwise, the return value is a one-character string holding the e-ASCII code of the pressed key.
- When a function key F1 to F15 is pressed,
INKEY$will return the letters of the associated macro unless it's been set to empty with the KEY statement, in which case it returns the e-ASCII code for the function key.
code = INP(port)
Returns the value of a machine port.
port is a numeric expression in [0 to 65535].
position = INSTR([start,] parent, chlid)
Returns the location of the first occurrence of the substring chlid in parent.
- parent and child are string expressions.
-
start is a numeric expression in
[1 to 255], specifying the starting position from where to look; if not specified, the search starts at character 1.
- If child is not a substring of parent occurring at or before start,
INSTRreturns0. - If the start index is
0(instead of1), it still searches from the beginning. - If child is empty, it is found right away at the start index.
- start has a string value or parent or child have numeric values: Type mismatch.
-
start is not in
[-32768 to 32767]: Overflow. -
start is not in
[1 to 255]: Illegal function call.
whole = INT(number)
Returns number truncated towards negative infinity.
number is a numeric expression.
FIX truncates towards zero: it removes the fractional part. By contrast, INT truncates towards negative infinity.
number is a string expression, Type mismatch .
child = LEFT$(parent, num_chars)
...
length = LEN(string)
Returns the number of characters in string.
string is a string expression.
string has a number value: Type mismatch.
y = LOG(x)
Returns the natural logarithm of x.
x is a numeric expression greater than zero.
-
xhas a string value: Type mismatch. -
xis zero or negative: Illegal function call.
substring = MID$(string, position [, length])
...
value = PEEK(address)
Returns the value of the memory at segment * 16 + address where segment
is the current segment set with DEF SEG.
address is a numeric expression in [-32768 to 65535]. Negative values are interpreted as their two's complement.
Currently PEEK only accepts values in the range [0 to 65535] and ignores SEG, returning values from the 64K address space.
-
addresshas a string value: Type mismatch. -
addressis not in[-32768 to 65535]: Overflow.
child = RIGHT$(parent, num_chars)
...
random = RND[(x)]
Returns a pseudorandom number in the interval `0 to 1).
x is a numeric expression.
- If
xis zero,RNDrepeats the last pseudo-random number. - If
xis greater than zero, a new pseudorandom number is returned. - If
xis negative,xis converted to a single-precision floating-point value and the random number seed is set to the absolute value of its mantissa. The function then generates a new pseudorandom numer with this seed. Since the only the mantissa ofxis used, any two values whose ratio is a power of 2 will produce the same seed. Note that this procedure for generating a new seed differs from that used by RANDOMIZE.
- SE Basic IV's
RNDfunction produces different random numbers from Microsoft BASIC. - It is a very poor random number generator.
RNDshould not be used for cryptography, scientific simulations or anything else remotely serious.
-
xhas a string value: Type mismatch.
sign = SGN(number)
Returns the sign of number: 1 for positive, 0 for zero and -1 for negative.
number is a numeric expression.
number has a string value: Type mismatch.
SIN
sine = SIN(angle)
Returns the sine of angle.
angle is a numeric expression giving the angle in radians.
angle has a string value: Type mismatch.
root = SQR(number)
Returns the square root of number.
number is a numeric expression.
number has a string value: Type mismatch
repr = STR$(number)
Returns the string representation of number.
number is a numeric expression.
number has a string value: Type mismatch.
string = STRING$(length, char)
Returns a string of length times the character char.
- If
charis a numeric expression, it must be in[0 to 255]and is interpreted as the code point of the character. - If
charis a string expression, its first character is used.
-
lengthhas a string value: Type mismatch. -
charis the empty string: Illegal function call. -
charorlengthis not in[-32768 to 32767]: Overflow. -
charorlengthis not in[0 to 255]: Illegal function call.
tangent = TAN(angle)
Returns the tangent of angle.
angle is a numeric expression giving the angle in radians.
angle has a string value: Type mismatch.
value = USR[n](expr)
Calls a machine-code function and returns its return value.
-
nis a digit<b>0</b> to <b>9</b>. -
expris an expression.
n is not a digit [0 to 9]: Syntax error.
VAL
value = VAL(string)
Returns the numeric value of the string expression string. See the section on numeric literals for the recognised number formats.
- Spaces before a number are ignored:
VAL(" 10")returns10. But unlike Microsoft BASIC, spaces inside a number are not ignored. - Unlike Microsoft BASIC, expressions inside the string expression are also evaluated. For example,
VAL "5+5"returns 10 andVAL "foo"returns the value of variablefoo. - Expressions between curly braces
{and}are not evaluated, but their syntax is checked upon entering. They are interpreted as strings that can be passed to VAL for actual evaluation.
string has a number value: Type mismatch.
repr = VAL$(string)
Evaluates a string as a string expression. For example
10 INPUT a$, x$
20 PRINT VAL$ a$
The string value assigned to a$ should be an expression using x$. For example, "x$+x$". A string value is then assigned to x$, for example "yo". VAL$ strips the quotes of the value of a$ to get x$+x$ and evaluates it using the value assigned to x$ displaying the result yoyo.
- This function is not present in Microsoft BASIC. It is very useful for creating recursive functions, if used together with
ANDapplied to string arguments, allowing for selective evaluation. - Expressions between curly braces
{and}are not evaluated, but their syntax is checked upon entering. They are interpreted as strings that can be passed to VAL$ for actual evaluation.
BEEP
Beep the speaker at approximately 800Hz for 0.25s.
BLOAD file_spec , offset
Loads a memory image file into memory.
- The string expression
file_specis a valid file specification indicating the file to read the memory image from. -
offsetis a numeric expression in the range[-32768 to 65535]. It indicates an offset in the current DEF SEG segment where the file is to be stored. If not specified, the offset stored in the BSAVE file will be used. If negative, its two's complement will be used.
- The loaded file is not in
BSAVEformat: Bad file mode. -
file_speccontains disallowed characters: Bad file number (onCAS1:); Bad file name (on disk devices). -
file_spechas a numeric value: Type mismatch. -
offsetis not in the range[-32768 to 65535]: Overflow.
BSAVE file_spec, offset, length
Saves a region of memory to an image file.
- The string expression
file_specis a valid file specification indicating the file to write to. -
offsetis a numeric expression in the range[-32768 to 65535]indicating the offset into the current [DEF SEG](#DEF-SEG"> segment from where to start reading. -
lengthis a numeric expression in the range[-32768 to 65535]indicating the number of bytes to read. - If
offsetorlengthare negative, their two's complement will be used.
-
file_spechas a numeric value: Type mismatch. -
file_speccontains disallowed characters: Bad file number (onCAS1:); Bad file name (on disk devices). -
offsetis not in the range[-32768 to 65535]: Overflow. -
lengthis not in the range[-32768 to 65535]: Overflow.
CALL address_var [, p0, p1, ...]
Executes a machine language subroutine.
-
address_varis a numeric variable. -
p0, p1, ...are variables.
-
address_varis a string variable: Type mismatch. -
address_varis a literal: Syntax error.
CHDIR dir_spec
Change the current folder on a disk device to dir_spec. Each disk device has its own current folder.
- The string expression
dir_specis a valid file specification indicating an existing folder on a disk device.
- No matching path is found: Path not found.
-
dir_spechas a numeric value: Type mismatch. -
dir_specis empty: Bad file name.
CIRCLE x , y , r
Draws a circle where x and y are the center coordinates and r is the radius.
CLEAR [mem_limit]
Clears all variables, arrays, DEF FN user functions. Closes all files. Turns off all sound. Clears all ON ERROR traps. Clears the loop stack.
mem_limit specifies the upper limit of usable memory. Default is previous memory size. Default memory size is 65535.
- If called inside a FOR to NEXT or WHILE to WEND loop, an error will be raised at the
NEXTorWENDstatement, since the loop stacks have been cleared.
- Any of the arguments has a string value: Type mismatch.
-
mem_limitis not in[0 to 65535]: Overflow. -
mem_limitis too low: Address out of range.
CLOSE [[#] file_0 [, [#] file_1] ...]
Closes streams. If no file numbers are specified, all open streams [3 to 15] are closed. The hash (#) is optional and has no effect.
-
file_1, file_2, ...are numeric expressions yielding stream numbers.
-
file_1, file_2, ...are not in[0 to 15]: Bad I/O device. -
file_1, file_2, ...are not open streams: Undefined stream. -
file_1, file_2, ...have a string value: Type mismatch. - The statement ends in a comma, Syntax error.
- If an error occurs, only the files before the erratic value are closed.
CLS [x]
Clears the screen or part of it. If x is not specified, in SCREEN 0 the text view region is cleared; in other screens, the graphics view region is cleared. The comma is optional and has no effect.
x is a numeric valued expression that determines what is cleared:
- If
x = 0, the whole screen is cleared. - If
x = 1, the graphics view region is cleared. - If
x = 2, the text view region is cleared.
-
xis has a string value: Type mismatch. -
xis not in[-32768 to 32767]: Overflow . -
xis not in[0, 1, 2]: Illegal function call. - If an error occurs, the screen is not cleared.
COLOR foreground, background [, border]
Changes the current foreground and background attributes. All new characters printed will take the newly set attributes. Existing characters on the screen are not affected.
-
foregroundis a numeric expression in[0 to 15]. This specifies the new foreground attribute. -
backgroundis a numeric expression in0 to 15. This specifies the new background attribute. -
borderis a numeric expression in[0 to 15]specifying the border attribute. It is takenMOD 8: Values8 to 15produce the same colour as0 to 7.
- Any of the parameters has a string value: Type mismatch.
- Any of the parameters is not in
[-32768 to 32767]: Overflow. -
foregroundis not in[0 to 31],backgroundis not in[0 to 15]orborderis not in[0 to 15]: Illegal function call. - Statement is used in
SCREEN 2: Illegal function call.
COPY file_spec_1 TO file_spec_2
Copies the disk file file_spec_1 to file_spec_2.
The string expressions file_spec_1 and file_spec_2 are valid file specifications indicating the source and destination files. The first must point to an existing file on a disk device.
Typically, this command is not present in Microsoft BASIC.
-
file_spec_1orfile_spec_2have number values: Type mismatch -
file_spec_1does not exist: File not found
CONT
Resumes execution of a program that has been halted by STOP, END or Esc.
- Anything after the
CONTkeyword is ignored. - This statement can only be used in direct mode.
- If a break is encountered in GOSUB routine called from a continuing direct line (for example,
GOSUB 100:PRINT A$),CONTwill overwrite the running direct line. As the subroutine RETURNs to the position after theGOSUBin the old direct line, strange things may happen if commands are given afterCONT. In Microsoft BASIC, this can lead to strange errors in non-existing program lines as the parser executes bytes that are not part of a program line. In SE Basic IV, if the new direct line is shorter, execution stops afterRETURN; but if the direct line is extended beyond the old return position, the parser tries to resume at that return position, with strange effects.
- No program is loaded, a program has not been run, after a program line has been modified or after CLEAR: Can't continue.
- The break occurred in a direct line: Can't continue.
-
CONTis used in a program: Can't continue.
DATA [const_0] [, [const_1]] ...
Specifies data that can be read by a READ statement.
const_0, const_1, ... are string and number literals or may be empty. String literals can be given with or without quotation marks. If quotation marks are omitted, leading and trailing whitespace is ignored and commas or colons will terminate the data statement.
If the type of the literal does not match that of the corresponding READ statement, a Syntax error occurs on the DATA statement.
DEF FN[ ]name [( arg_0 [, arg_1] ...)] = expression
Defines a function called FN name (or FN name: spaces between FN and name are optional). On calling FNname( ... ), expression is evaluated with the supplied parameters substituted. Any variable names used in the function that are not in the argument list refer to the corresponding global variables. The result of the evaluation is the return value of FNname. The type of the return value must be compatible with the type indicated by name.
Create the recursive function FN F(n) to calculate the factorial for n:
DEF FN F(N)=VAL (({N*FN F(N-1)} AND N)+({1} AND (N=0)))
- This statement may only be used on a program line.
- As the function must be a single expression and SE Basic IV does not have a ternary operator, the only way to define a recursive function that actually terminates is by using VAL or VAL$.
- Do not use the function that you defining within its own definition. This will corrupt BASIC when the function is called. For example:
DEF FN A()=FN A():PRINT FN A().
-
namemust be a legal variable name. -
arg_0, arg_1, ...must be legal variable names. These are the parameters of the function. Variables of the same name may or may not exist in the program; their value is not affected or used by the defined function. -
expressionmust be a legal SE Basic IV expression.
- The statement is executed directly instead of in a program line: Illegal direct.
- If the type of the return value is incompatible with the type of
name, no error is raised at theDEF FNstatement; however, a Type mismatch will be raised at the first call ofFNname.
DELETE [line_number_0|.] [-[line_number_1|.] ]
Deletes a range of lines from the program. Also stops program execution and returns control to the user.
-
line_number_0andline_number_1are line numbers in the range[0 to 65529], specifying the inclusive range of line numbers to delete. - A
.indicates the last line edited. - If the start point is omitted, the range will start at the start of the program.
- If the end point is omitted, the range will end at the end of the program.
- If no range is specified, the whole program will be deleted.
-
line_number_0orline_number_1is greater than65529: Syntax error. - The range specified does not include any program lines stored: Illegal function call.
DIM name {(|[} limit_0 [, limit_1] ... {)|]}
Allocates memory for arrays. The DIM statement also fixes the number of indices of the array. An array can only be allocated once; to re-allocate an array, ERASE or CLEAR must be executed first. If an array is first used without a DIM statement, it is automatically allocated with its maximum indices set at 10 for each index position used. If an array's DIM statement specifies no indices, it is allocated with a single index with maximum 10. The least index allowed is determined by OPTION BASE.
-
nameis a legal variable name specifying the array to be allocated. -
limit_0, limit_1, ...are numeric expressions that specify the greatest index allowed at that position.
- Mixed brackets are allowed.
- The size of arrays is limited by the available BASIC memory.
- The maximum number of indices is, theoretically,
255. In practice, it is limited by the 255-byte limit on the length of program lines.
-
namehas already been dimensioned: Duplicate definition. - An index is empty: Syntax error.
- An index is missing at the end: Missing operand.
-
limit_0, limit_1, ...have a string value: Type mismatch. -
limit_0, limit_1, ...are not within[-32768 to 32767]: Overflow. -
limit_0, limit_1, ...are negative: Illegal function call. - The array exceeds the size of available variable space: Out of memory.
DOKE address, value
Sets the 16-bit value of the memory byte pair at segment * 16 + address to value, where segment is the current segment set with DEF SEG.
-
addressis a numeric expression in[0 to 65535]. Negative values are interpreted as their two's complement. -
valueis a numeric expression in[0 to 65535].
-
DEF SEGis not yet implemented in SE Basic IV.
-
addressorvaluehas a string value: Type mismatch. -
addressis not in[-32768 to 65535]: Overflow. -
valueis not in[-32768 to 32767]: Overflow. -
valueis not in[0 to 65535]: Illegal function call.
DRAW x , y
Draws a line x pixels to the right and y pixels up from the last PLOT location. Accepts negative values.
EDIT {line_number|.}
Displays the specified program line with the cursor positioned for editing. line_number must be a line that exists in the program, or a period (.) to indicate the last line stored.
- No line_number is specified: Undefined line number.
- More characters are written after the line number: Illegal function call.
-
line_numberis not in[0 to 65529]Illegal function call. - The specified line number does not exist: Undefined line number.
ELSE [anything]
Unless part of an IF statement on the same line, anything after ELSE is ignored in the same way as after ' or :REM. Unlike Microsoft BASIC, a colon : preceding the ELSE statement is required. However, if you enter a space before ELSE the tokenizer will add the colon for you. See IF for normal usage.
END
Closes all files, stops program execution and returns control to the user. No message is printed. It is possible to resume execution at the next statement using CONT.
ERROR error_number
Raises the error with number error_number.
-
error_numberis an expression with a numeric value.
-
error_numberhas a string value: Type mismatch. -
error_numberis not in[-32768 to 32767]: Overflow. -
error_numberis not in1 to 255]: Illegal function call.
FILES [filter_spec]
Displays the files fitting the specified filter in the specified folder on a disk device. If filter_spec is not specified, displays all files in the current working folder.
-
filter_specis a string expression that is much like a file specification, but optionally allows the file name part to contain wildcards.
Wildcards are not currently supported.
-
filter_spechas a numeric value: Type mismatch. -
filter_specis the empty string: Bad file name. - The specified filter does not match any files: File not found.
FOR loop_var = start TO stop [STEP step]
Initiates a FOR to NEXT loop.
Initially, loop_var is set to start. Then, the statements between the FOR statement and the [](#NEXT">NEXT statement are executed and loop_var is incremented by step (if step is not specified, by 1). This is repeated until loop_var has become greater than stop. Execution then continues at the statement following NEXT. The value of loop_var equals stop+step after the loop.
-
loop_varis a numeric variable. -
start,stopandstepare numeric expressions.
- No
NEXTstatement is found to match theFORstatement: FOR without NEXT occurs at theFORstatement. -
loop_varis a string variable orstart,stop, orendhas a string value: Type mismatch. -
loop_varis an array element: Syntax error . -
loop_varis an integer variable and astart,stoporstepis outside the range[-32768, 32767]: Overflow .
GO[ ]SUB line_number [anything]
Jumps to a subroutine at line_number. The next [](#RETURN">RETURN statement jumps back to the statement after GOSUB. Anything after line_number until the end of the statement is ignored. If executed from a direct line, GOSUB runs the subroutine and the following RETURN returns execution to the direct line.
-
line_numberis an existing line number literal. - Further characters on the line are ignored until end of statement.
- If no
RETURNis encountered, no problem. - One optional space is allowed between
GOandSUB; it will not be retained in the program.
- If
line_numberdoes not exist: Undefined line number. - If
line_numberis greater than65529, only the first 4 characters are read (for example,6553)
GOTO line_number [anything]
Jumps to line_number. Anything after line_number until the end of the statement is ignored. If executed from a direct line, GOTO starts execution of the program at the specified line.
-
line_numberis an existing line number literal. - Further characters on the line are ignored until end of statement.
No spaces are allowed between GO and TO.
-
line_numberdoes not exist: Undefined line number.
IF truth_value {THEN|GOTO} [compound_statement_true|line_number_true [anything]] [ELSE [compound_statement_false|line_number_false [anything]]]
If truth_value is non-zero, executes compound_statement_true or jumps to line_number_true . If it is zero, executes compound_statement_false or jumps to line_number_false .
-
truth_valueis a numeric expression. -
line_number_falseandline_number_trueare existing line numbers. -
compound_statement_falseandcompound_statement_trueare compound statements, consisting of at least one statement, optionally followed by further statements separated by colons:. The compound statements may contain nestedIF to THEN to ELSEstatements.
- The comma is optional and ignored.
-
ELSE clauses are optional; they are bound to the innermost free
IFstatement if nested. AdditionalELSEclauses that have no matchingIFare ignored. - All clauses must be on the same program line.
-
THENandGOTOare interchangeable; which one is chosen is independent of whether a statement or a line number is given.GOTO PRINT 1` is fine. - As in GOTO, anything after the line number is ignored.
- If
truth_valuehas a string value: Type mismatch. -
truth_valueequals0andline_number_falseis a non-existing line number, ortruth_valueis nonzero andline_number_trueis a non-existing line number: Undefined line number.
INPUT [;] [prompt {;|,}] var_0 [, var_1] ...
Prints prompt to the screen and waits for the user to input values for the specified variables. The semicolon before the prompt, if present, stops a newline from being printed after the values have been entered. If the prompt is followed by a semicolon, it is printed with a trailing ?. If the prompt is followed by a comma, no question mark is added.
-
promptis a string literal. -
var_0, var_1, ...are variable names or fully indexed array elements.
- Values entered must be separated by commas. Leading and trailing whitespace is discarded.
- String values can be entered with or without double quotes (
"). - If a string with a comma, leading or trailing whitespace is needed, quotes are the only way to enter it.
- Between a closing quote and the comma at the end of the entry, only white- space is allowed.
- If quotes are needed in the string itself, the first character must be neither a quote nor whitespace. It is not possible to enter a string that starts with a quote through
INPUT. - If a given
var_nis a numeric variable, the value entered must be number literal. - Characters beyond the 255th character of the screen line are discarded.
- If user input is interrupted by Ctrl+Break, [](#CONT">CONT will re-execute the
INPUTstatement.
- If the value entered for a numeric variable is not a valid numeric literal, or the number of values entered does not match the number of variables in the statement, ?Redo from start is printed and all values must be entered again.
- A Syntax error that is caused after the prompt is printed is only raised after the value shave been entered. No values are stored.
KEY key_id, string_value
Defines the string macro for functino key key_id. Only the first 15 characters of string_value are stored.
-
key_idis a numeric expression in the range[1 to 15]. -
string valueis a string expression.
- If
key_idis not in the prescribed range, an error is raised. - If
string_valueis the empty string or the first character ofstring_valueisCHR$(0), the function key macro is switched off and subsequent catching of the associated function key with INKEY$ is enabled.
-
key_idis not in[-32768 to 32767]: Overflow. -
key_idis not in[1 to 255]: Illegal function call. -
key_idhas a string value: Type mismatch.
KEY LIST
Prints a list of the 15 function keys with the functino-key macros defined for those keys to the console.
Most characters are represented by their symbol equivalent in the current codepage. However, some characters get a different represenation, which is a symbolic representation of the effect as control characters on the screen.
| Code point | Replacement | Usual glyph |
|---|---|---|
$07 |
$0E |
♫ |
$08 |
$FE |
■ |
$09 |
$1A |
→ |
$0A |
$1B |
← |
$0B |
$7F |
⌂ |
$0C |
$16 |
▬ |
$0D |
$1B |
← |
$1C |
$10 |
► |
$1D |
$11 |
◄ |
$1E |
$18 |
↑ |
$1F |
$19 |
↓ |
KEY {ON|OFF}
Toggles function-key macros ON or OFF.
KILL file_spec
Deletes a file on a disk device.
The string expression file_spec is a valid file specification indicating the file to delete. It must point to an existing file on a disk device.
-
file_spechas a number value: Type mismatch. - The file
file_specis open: File already open - The file or path
file_specdoes not exist: File not found - The user has no write permission: Permission denied
- If a syntax error occurs after the closing quote, the file is removed anyway.
[LET] name = expression
Assigns the value of expression to the variable or array element name.
-
nameis a variable that may or may not already exist. - The type of
expressionmatches that ofname: that is, all numeric types can be assigned to each other but strings can only be assigned to strings.
name and expression are not of matching types: Type mismatch.
LIST [# file_num;] [line_number_0][, ][line_number_1]
Prints the program to the screen or a file, starting with line_number_0 up to and including line_number_1. Also stops program execution and returns control to the user. In all cases, any further statements in a compound after LIST will be ignored, both in a program and in direct mode.
When listing to the screen, the same control characters are recognised as in the PRINT statement.
- In Microsoft BASIC,
LISTwill not show line numbers65531to65535inclusive. - SE Basic IV's line range is currently
[0 to 16383]. - There is no
LLISTcommand. Instead,LISTcan be directed to the printer stream usingLIST #.
-
line_number_0andline_number_1are line numbers in the range[0 to 65529]or a.to indicate the last line edited. The line numbers do not need to exist; they specify a range. If the range is empty, nothing is printed. - The string expression
file_numis a valid stream indicating the file to list to.
- A line number is greater than
65529: Syntax error. -
file_numhas a string value: Type mismatch.
LOAD file_spec [,{"R"|"T"}]
Loads the program stored in a file into memory. Existing variables will be cleared and any program in memory will be erased. LOAD implies a [CLEAR](#CLEAR).
If ,"R" is specified, keeps all data files open and runs the specified file.
If ,"T" is specified, loads a tokenized program.
The string expression file_spec is a valid file specification indicating the file to read the program from.
- Unlike Microsoft BASIC, SE Basic IV always expects BASIC programs to be in plain text format.
- Unlike Microsoft BASIC, the
Rdirective must be in quotes. Otherwise SE Basic IV would treat it as a variable.
-
file_spechas a numeric value: Type mismatch. -
file_speccontains disallowed characters: Bad file number (onCAS1:); Bad file name (on disk devices). - The file specified in
file_speccannot be found: File not found. - A loaded text file contains lines without line numbers: Direct statement in file.
- A loaded text file contains lines longer than 255 characters: Line buffer overflow. Attempting to load a text file that has
LFrather thanCR LFline endings may cause this error.
LOCATE [row] , [col]
Set the next print position to row, col on the screen.
- In Microsoft BASIC, the cursor can be displayed or made invisible and its shape can be changed. This is not supported in SE Basic IV.
- Any parameter has a string value: Type mismatch.
- Any parameter is not in
[-32768 to 32767]: Overflow. -
rowis outside the current view area: Illegal function call. -
colis greater than the current width: Illegal function call. -
cursor_visibleis not in[0, 1]([0 to 255]on Tandy/PCjr): Illegal function call.
MERGE file_spec
Merges the program stored in a file into memory.
The string expression file_spec is a valid file specification indicating the file to read the program from.
Unlike Microsoft BASIC, SE Basic IV always expects BASIC programs to be in plain text format.
-
file_spechas a numeric value: Type mismatch. -
file_speccontains disallowed characters: Bad file number (onCAS1:); Bad file name (on disk devices). - The file specified in
file_speccannot be found: File not found. - A loaded text file contains lines without line numbers: Direct statement in file.
- A loaded text file contains lines longer than 255 characters: Line buffer overflow. Attempting to load a text file that has
LFrather thanCR LFline endings may cause this error.
MKDIR dir_spec
Creates a new folder on a disk device.
The string expression dir_spec is a valid file specification that specifies the path of the new folder on a disk device.
-
dir_specis not a string: Type mismatch. - The parent folder does not exist: Path not found.
- The folder name already exists on that path: Path/File access error.
- The user has no write permission: Permission denied.
NAME old_name TO new_name
Renames the disk file old_name into new_name.
- The string expressions
old_nameandnew_nameare valid file specifications giving the path on a disk device to the old and new filenames, respectively.
new_name will be modified into all-uppercase 8.3 format.
-
old_nameornew_namehave number values: Type mismatch. -
old_namedoes not exist: File not found. -
old_nameis open: File already open. -
new_nameexists: File already exists.
NEW
Stops execution of a program, deletes the program in memory, executes CLEAR and RESTORE and returns control to the user.
NEXT [var_0 [, var_1] ...]
Iterates a FOR to NEXT loop: increments the loop variable and jumps to the [](#FOR">FOR statement. If no variables are specified, next matches the most recent FOR statement. Several nested NEXT statements can be consolidated into one by using the variable list. If one or more variables are specified, their order must match the order of earlier FOR statements.
var_0, var_1, ... are numeric variables which are loop counters in a FOR statement.
- No
FORstatement is found to match theNEXTstatement and variables: NEXT without FOR. -
var_0, var_1, ...are string variables: NEXT without FOR. - The (implicit or explicit) loop variable is an integer variable and is taken outside the range
[-32768, 32767]when incremented after the final iteration: Overflow.
OLD
Loads a backup from disk of the program that was in memory the last time a NEW command was issued and returns control to the user.
ON n {GOTO|GOSUB} line_number_0 [, line_number_1] ...
Jumps to the nth line number specified in the list. If n is 0 or greater than the number of line numbers in the list, no jump is performed. If GOTO is specified, the jump is unconditional; if GOSUB is specified, jumps to a subroutine.
-
nis a numeric expression in[0 to 255]. -
line_number_0, <var>line_number_1, ...are existing line numbers in the program.
-
nhas a string value: Type mismatch. -
nis not in[-32768 to 32767], Overflow. -
nis not in[0 to 255]: Illegal function call. - The line number jumped to does not exist: Undefined line number.
ON ERROR GOTO {line_number|0}
Turns error trapping on or off. When line_number is set, any error causes the error handling routine starting at that line number to be called; no message is printed and program execution is not stopped. The error handling routine is ended by a [](#RESUME">RESUME statement. While in an error handling routine, events are paused and error trapping is disabled. After the RESUME statement, any triggered events are picked up in the following order: KEY, TIMER, PLAY - the order of the others is unknown. Unlike event trapping, error trapping remains active when no program is running. ON ERROR GOTO 0 turns off error trapping.
line_number is an existing line number in the program.
It is not possible to start the error handler at line number 0.
line_number does not exist: Undefined line number.
OPEN # file_num, "mode_char" [,file_spec]
Opens a data file on a device.
- The string expression file_spec is a valid file specification.
-
file_num is a valid stream
[3 to 15]. -
mode_char is a string expression of which the first character is one of:
-
["K", "S"]- system channel (keyboard or screen). - `["I", "O", "A", "R"] - access mode for a disk file.
- other alpha character - a used defined channel.
-
The mode_char are as follows:
| mode_char | Meaning | Effect |
|---|---|---|
| "I" | INPUT | Opens a text file for reading and positions the file pointer at the start. |
| "O" | OUTPUT | Truncates a text file at the start and opens it for writing. Any data previously present in the file will be deleted. |
| "A" | APPEND | Opens a text file for writing at the end of any existing data. |
| "R" | RANDOM | Opens a file for random access. |
A single character can be read with c$=INKEY$ #file_num or written with PRINT #file_num;c$;. Strings are terminated with a carriage return. A string can be read with INPUT #file_num;s$ or written with PRINT #file_num;s$.
file_spec is a non-empty string expression of the form "parameters".
parameters must specify a valid file path of the form [/][dirname/] ... filename.
In SE Basic IV, file support is provided using the OS kernel. UnoDOS 3 follows MS-DOS file system conventions with the exception that folder names are separated with forward slashes (/). SE Basic IV adds syntactic sugar to the short filename format. File names consist of an 8-character name and 3-character extension. Folder names consist of an 11-character name. Permissible characters are the printable ASCII characters in the range [$20 to $7E] excluding the characters " * + . , / : ; < = > ? \ [ ] |. Spaces are allowed but are converted to underscores.
A path starting with a forward slash is interpreted as an absolute path, starting at the root of the specified disk device. Otherwise, the path is interpreted as relative to the current folder on the specified device. The special folder name .. refers to the parent folder of a preceding path, or the parent folder of the current folder if no path is given. The special folder name . refers to the same folder as given by the preceding path, or the current folder if no preceding path is given.
The LOAD and SAVE statements do not currently implicitly add a default extension .BAS if no extension is specified..
UnoDOS 3 allows certain characters in the range $7F to $FF. However, their permissibility and interpretation depends on the console code page, which may be different from the display code page currently in use. Therefore you should avoid using these characters.
- file_num is a non-existent stream: Undefined stream.
-
file_num is not in range
[0 to 15]: Bad I/O device. - mode_char is a non-existent channel: Undefined channel.
- file_spec is non-existent in input or append mode: File not found.
OUT port, value
Sends a byte to an emulated machine port.
-
portis a numeric expression in[0 to 65535]. -
valueis a numeric expression in[0 to 255].
-
portorvaluehas a string value: Type mismatch. -
portis not in[0 to 65535]: Overflow. -
valueis not in[0 to 32767]: Overflow. -
valueis not in[0 to 255]: Illegal function call.
PALETTE [attrib, color]
Assigns a colour to an attribute. All pixels with that attribute will change colour immediately. If no parameters are specified, PALETTE resets to the initial setting.
-
attribis a numeric expression from[0 to 63]. -
coloris a numeric expression between[0 and 255]
Colors are entered in compressed RGB format (lowest to highest bit). The red and green levels are each stored in three bits (0 to 7) while the blue level is stored in two bits (0 to 3). The easiest way to enter values is in octal (@BGR). For example, to set attribute to maximum blue, you would enter PALETTE attribute, @300.
-
attriborcolourhas a string value: Type mismatch. -
attriborcolouris not in[ to 32767]: Overflow -
attriborcolouris not in range: Illegal function call
PLAY [# device,] string[, string[, ...]
PLAY up to 8 strings of music data in MML format to the square wave generator or GM-MIDI.
-
deviceis0(PSG) or1(MIDI). -
stringis a valid MML command sequence.
string is not valid MML: Syntax error
SE Basic IV implements a version of MML (Music Macro Language).
- Other than note names (
c,d,e,f,g,a,b), commands are case-insensitive. - Upper case notes (
C,D,E,F,G,A,B) are one octave higher than the current octave. - The default octave is
4. -
Ris a rest. -
-before a note flattens it. -
+or#before a note sharpens it. -
&indicates tied notes. - Comments can be enclosed between single quote marks (
'). -
Osets the octave (1to8). - (optional)
Lsets the note length (0to9) as classic MML, or triplets (10to12). - Phrases in square brackets (
[``]) are played twice. - Brackets can be nested up to four levels.
- A closing bracket without a matching opening bracket loops the preceding phrase indefinitely.
-
Tsets the tempo in BPM (32to255, default120). -
Vsets the volume (0to15) and switches off envelopes on that channel. -
Ssets the envelope waveform (0to15) and activates it. -
Msets the modulation frequency (1to65536). -
Hsets the MIDI channel (1to16). -
Zsends a command (0to255) to the MIDI port. -
Xexits the PLAY command immediately. -
>increases the octave by one. -
<decreases the octave by one
PLOT x , y
Draws a pixel at coordinates x and y.
POKE address, value
Sets the value of the memory byte at segment * 16 + address to value, where segment is the current segment set with DEF SEG.
-
addressis a numeric expression in[-32768 to 65535]. Negative values are interpreted as their two's complement. -
valueis a numeric expression in[0 to 255].
-
DEF SEGis not yet implemented in SE Basic IV.
-
addressorvaluehas a string value: Type mismatch. -
addressis not in[-32768 to 65535]: Overflow. -
valueis not in[-32768 to 32767]: Overflow. -
valueis not in[0 to 255]: Illegal function call.
PRINT [# stream,] [expr_0|;|,|SPC( n)|TAB( n)] ... [USING format; uexpr_0 [{;|,} uexpr_1] ... [;|,]]
Writes expressions to the screen, a file or another device. If stream is specified, output goes to the file or device open under that number. ? is a shorthand for PRINT.
When writing a string expression to the screen, the following control characters have special meaning. Other characters are shown as their corresponding glyph in the current codepage.
| Code point | Control character | Effect |
|---|---|---|
$07 |
BEL |
Beep the speaker. |
$08 |
BS |
Erase the character in the previous column and move the cursor back. |
$09 |
HT |
Jump to the next 8-cell tab stop. |
$0A |
LF |
Go to the leftmost column in the next row; connect the rows to one logical line. |
$0B |
VT |
Move the cursor to the top left of the screen. |
$0C |
FF |
Clear the screen. |
$0D |
CR |
Go to the leftmost column in the next row. |
$1C |
FS |
Move the cursor one column to the right. |
$1D |
GS |
Move the cursor one column to the left. |
$1E |
RS |
Move the cursor one row up. |
$1F |
US |
Move the cursor one row down. |
Note: In SE Basic IV, anything after PRINT CHR$(12) is not printed.
Expressions can optionally be separated by one or more of the following keywords:
| Keyword | Effect |
|---|---|
; |
Attaches two expressions tight together; strings will be printed without any space in between, numbers will have one space separating them, in addition to the space or minus sign that indicate the sign of the number. |
, |
The expression after will be positioned at the next available tab stop. |
' |
Inserts a newline. |
SPC(n) |
Produces n spaces, where n is a numeric expression. If n is less than zero, it defaults to zero. If n is greater than the file width, it is taken modulo the file width. |
TAB(n) |
Moves to column n, where n is a numeric expression. if n is less than zero, it defaults to zero. If n is greater than the file width, it is taken modulo the file width. If the current column is greater than n, TAB moves to column n on the next line. |
If the print statement does not end in one of these four separation tokens, a newline is printed after the last expression. String expressions can be separated by one or more spaces, which has the same effect as separating by semicolons.
RANDOMIZE [expr]
Seeds the random number generator with expr. If no seed is specified, RANDOMIZE will prompt the user to enter a random seed. The user-provided value is rounded to an integer. The random seed is formed of the last two bytes of that integer or expr. If expr is a float (4 or 8 bytes), these are [](#boolean-operators">XORed with the preceding 2. The first 4 bytes of a double are ignored. The same random seed will lead to the same sequence of pseudorandom numbers being generated by the [](#RND">RND function.
expr is a numeric expression.
- For the same seed, SE Basic IV produces the same pseudorandom numbers as Microsoft BASIC 3.23.
- The random number generator is very poor and should not be used for serious purposes. See [](#RND">RND for details.
-
exprhas a string value: Illegal function call. - The user provides a seed outside
[-32768 to 32767]at the prompt: Overflow.
READ var_0 [, var_1] ...
Assigns data from a [](#DATA">DATA statement to variables. Reading starts at the current DATA position, which is the DATA entry immediately after the last one read by previous READ statements. The DATA position is reset to the start by the [](#RUN">RUN and [](#RESTORE">RESTORE statements.
var_0, var_1 are variables or array elements.
- Not enough data is present in
DATAstatements: Out of DATA. - The type of the variable is not compatible with that of the data entry being read: a Syntax error occurs on the
DATAline.
{REM|'} [anything]
Ignores everything until the end of the line. The REM statement is intended for comments. Everything after REM will be stored in the program unaltered and uninterpreted. Apostrophe (') is an alias for REM.
Note that a colon : does not terminate the REM statement; the colon and everything after it will be treated as part of the comment.
RENUM [new|.] [, [old|.] [, increment]]
Replaces the line numbers in the program by a systematic enumeration starting from new and increasing by increment. If old is specified, line numbers less than old remain unchanged. new, old are line numbers; the dot . signifies the last line edited. increment is a line number but must not be a dot or zero.
- The following keywords can reference line numbers, which will be renumbered by
RENUM: GOSUB, GOTO, LIST, RESTORE, RUN.
- Any of the parameters is not in
[0 to 65529]: Syntax error. - Any of the newly generated line numbers is greater than
65529: Illegal function call. The line numbers up to the error have not been changed. -
incrementis empty or zero: Illegal function call. -
oldis specified andnewis less than or equal to an existing line number less than old: Illegal function call.
RESTORE [line]
Resets the DATA pointer. line is a line number. If line is not specified, the DATA pointer is reset to the first DATA entry in the program. If it is specified, the DATA pointer is reset to the first DATA entry in or after line.
line is not an existing line number: Undefined line number.
RETURN [line]
Returns from a GOSUB subroutine. If line is not specified, RETURN jumps back to the statement after the GOSUB that jumped into the subroutine. If line is specified, it must be a valid line number. RETURN jumps to that line (and pops the GOSUB stack). When returning from an error trapping routine, RETURN re-enables the event trapping which was stopped on entering the trap routine.
line is not an existing line number: Undefined line number.
RMDIR dir_spec
Removes an empty folder on a disk device.
The string expression dir_spec is a valid file specification that specifies the path and name of the folder.
-
dir_spechas a numeric value: Type mismatch. -
dir_specis an empty string: Bad file name . - No matching path is found: Path not found .
RUN [line_number | app_name [, p0, p1, ...]]
Executes a program. Existing variables will be cleared and any program in memory will be erased. RUN implies a CLEAR. If an app_name is specified, opens the application.
-
line_numberis a valid line number in the current program. If specified, execution starts from this line number. The rest of theRUNstatement is ignored in this case. - The string expression
app_name, if specified, is a valid application name (case-insensitive, truncated to the first 11 characters). -
p0, p1, ...are variables.
-
line_numberis not a line number in the current program: Undefined line number. -
app_namecannot be found: File not found.
SAVE file_spec [,"T"]
Stores the current program in a file.
If ,"T" is specified, saves a tokenized program.
The string expression file_spec is a valid file specification indicating the file to store to.
In Microsofr BASIC you can append , A to save the file in plain text or , P to save a protected listing, otherwise the file is saved in tokenized format. In SE Basic IV the file is saved in plain text format unless you append , "T".
-
file_spechas a number value: Type mismatch. -
file_specis an empty string: Bad I/O device. -
file_specis too long: Bad I/O device.
SCREEN mode
Change the video mode. Video modes are described in the Video Modes section.
mode is a numeric expression that sets the screen mode.
| Video mode | Notes |
|---|---|
0 |
Text mode. 80 x 24 characters. Two attributes picked from 16 colors. |
1 |
Bitmap mode. 240 x 192 pixels. 40 x 24 characters of 6 x 8 pixels. 8 x 1 attributes from 16 colors. |
The driver for SCREEN 1 is stored in RAM and can be replaced with a driver for any screen mode supported by the hardware.
- No parameters are specified: Missing operand.
- Any parameter has a string value: Type mismatch.
- Any parameter is not in
[-32768 to 32767]: Overflow. -
modeis not an available video mode number for your video card setting: Illegal function call.
SEEK # file_num, loc
-
file_numis an open stream. -
locis a number between 0 and 2^32.
-
file_numis not open: Undefined stream. -
file_numis not a valid stream (3 to 15): Undefined stream.
SOUND frequency, duration [, volume [, voice]]
Produces a sound at frequency Hz for duration/18.2 seconds. On PCjr and Tandy, the volume and voice channel can additionally be specified.
If PLAY "MB" has been executed, SOUND plays in the background. If PLAY "MF" has been executed, sound plays in the foreground and the interpreter blocks until the sound is finished. Foreground mode is default. Unlike [](#PLAY">PLAY, the sound played by the most recent SOUND statement always plays in the background, even if PLAY "MF" has been entered. In background mode, each SOUND statement counts as 1 toward the length of the queue reported by the [](#PLAY-function">PLAY function.
-
frequencyis a numeric expression in[37 to 32767]or0(forsyntax={advanced | pcjr}) or in[-32768 to 32767](forsyntax=tandy). -
durationis a numeric expression in[0 to 65535]. -
volumeis a numeric expression in [0, 15]. 0 is silent, 15 is full volume; every step less reduces the volume by 2 dB. (Forsyntax={pcjr | tandy}) -
voiceis a numeric expression in [0, 2], indicating which of the three tone voice channels is used for this sound. (For [](#--syntax">syntax={pcjr | tandy})
- If
durationis zero, any active background sound is stopped and the sound queue is emptied. - If
durationis zero,volumeandvoicemust not be specified. - If
durationis less than.022but nonzero, the sound will be played in background and continue indefinitely until another sound statement is executed. This is also the behaviour for negativeduration. - If
frequencyequals32767or0, a silence of lengthdurationis queued.
- Any argument has a string value: Type mismatch.
-
frequencyis not in its allowed range, anddurationis not zero: Illegal function call. -
durationis zero and more than two arguments are specified: Syntax error. - [](#--syntax">syntax={ pcjr | tandy } is not set and more than two arguments are specified: Syntax error.
-
frequencyis not in[-32768 to 32767]: Overflow. -
durationis not in[-65535 to 65535]: Illegal function call. -
volumeis not in[0 to 15]: Illegal function call. -
voiceis not in[0 to 2]: Illegal function call.
STOP
Breaks program execution, prints a Break message on the console and returns control to the user. Files are not closed. It is possible to resume program execution at the next statement using CONT.
TRACE {ON|OFF}
Turns line number tracing on or off. If line number tracing is on, BASIC prints a tag [100] to the console when program line 100 is executed, and so forth.
Tracing is turned off by the NEW and LOAD statements.
WAIT frames
Pauses for (frames/60) seconds.
frames is in [0 to 65535].
In Microsoft BASIC, WAIT waits for input from a given port.
Any parameter has a string value: Type mismatch.
WEND
Iterates a WHILE—WEND loop: jumps to the matching WHILE statement, where its condition can be checked.
-
WHILE—WENDloops can be nested.WENDjumps to the most recentWHILEstatement that has not been closed by anotherWEND.
All previous WHILE statements have been closed by another WEND or no WHILE statement has been executed before: WEND without WHILE.
WHILE expr
Initiates a WHILE—WEND loop. If expr evaluates to zero, WHILE jumps to the statement immediately after the matching WEND. If not, execution continues.
expr is a numeric expression.
- No matching
WENDis found: WHILE without WEND. -
exprhas a string value: Type mismatch.
-
NEXT without FORA
NEXTstatement has been encountered for which no matchingFORcan be found. -
Syntax errorThe BASIC syntax is incorrect. A statement or expression has been mistyped or called in one of many incorrect ways. This error is also raised on a DATA line if a READ statement encounters a data entry of an incorrect format.
-
RETURN without GOSUBA
RETURNstatement has been encountered for which noGOSUBcall has been made. -
Out of DATAA READ statement is attempting to read more data entries than can be found from the current
DATAlocation onward. -
Illegal function callA statement, function or operator has been called with parameters outside the accepted range. This error is also raised for a large variety of other conditions – check the reference for the statement or function called.
-
OverflowA numeric expression result or intermediate value is too large for the required number format.
-
Out of memoryThere is not enough free BASIC memory to complete the operation. Too much memory is consumed by the program; variables, arrays and strings, or execution stacks for loops, subroutines or user-defined functions.
-
Undefined line numberA reference is made to a line number that does not exist in the program.
-
Subscript out of rangeAn array index (subscript) is used that is outside the range reserved for that array by the DIM statement.
-
Undefined variableA simple variable has been used without assigning it a value, or a control variable has been used with
NEXTwithout first setting it up in aFORstatement, or a subscripted value has been used before dimensioning the array withDIM. -
Address out of rangeThe value specified in a
CLEARstatement is either too big or too small. -
Statement missingA jump has been attempted to a statement that no longer exists.
-
Type mismatchThe expression used is of a type that cannot be converted to the required type for the function or statement. Most commonly, this is raised if a string argument is supplied to a statement or function that expects a number, or vice versa.
-
Out of screenINPUT has generated more than 23 lines in the lower part of the screen.
-
Bad I/O deviceFile handling report.
-
Undefined streamAttempted to read or write from a stream that has not been defined with an
OPENstatement. -
Undefined channelAttempted to open a stream to an unrecognized channel.
-
Undefined user functionThe
FNfunction is called with a function name for which no definition was made by aDEF FNstatement. -
Line buffer overflowThere is not enough memory space left to enter the new program line.
-
FOR without NEXTA
FORstatement has been encountered for which no matchingNEXTstatement can be found. -
WHILE without WENDA
WHILEstatement has been encountered for which no matchingWENDstatement can be found. -
WEND without WHILEA
WENDstatement has been encountered for which no matchingWHILEstatement can be found. -
File not foundA named file on a disk device cannot be found.
-
Input past endAn attempt is made to retrieve input from a file that has passed its end of file.
-
Path not foundAn
OPEN,MKDIR,RMDIR, orCHDIRstatement is executed referring to a (parent) path that does not exist on the disk device.
Break Program execution interrupted.
Ok Progam execution finished.
This documentation is copyright © 2012-2022 Source Solutions, Inc. Portions copyright © 2014-2019 Rob Hagemans.
Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.