-
-
Notifications
You must be signed in to change notification settings - Fork 7
Language guide
- Working with programs
- Control flow
- Arrays and variables
- Type conversion
- String operations
- Text and the screen
- The printer
- Keyboard input
- Function-key macros
- Calculations and maths
- Devices and files
- Graphics
- Sound
- Joystick and mouse
- Disks and DOS
- Serial communications
- Event handling
- Error handling
- User-defined functions
- Date and time
- Including data in a program
- Memory and machine ports
- Features not yet implemented
- Unsupported features
This documentation describes the SE Basic IV language, which aims to support programs written for Microsoft BASIC with minimal changes.
The Language Guide covers the language topic by topic, thematically grouping language elements used for a related purpose. Refer to the Language reference for a formal description of the language elements and their syntax.
Statement | Description |
---|---|
AUTO | Enter automatic line numbering mode. |
CHAIN | Load a new program and run it, preserving common variables. |
DELETE | Delete lines from the program. |
EDIT | Print a program line to the screen for editing. |
LIST | Print program lines to the screen. |
LIST # | Print program lines to another device. |
LOAD | Read a new program from file. |
MERGE | Overlay a program file onto the current program |
NEW | Clear the current program from memory. |
OLD | Restore the previously cleared program to memory. |
RENUM | Replace the program's line numbers. |
RUN | Start the current program. |
SAVE | Store the current program to file. |
TRON | Enable line number tracing. |
TROFF | Disable line number tracing. |
A program is normally executed starting with its lowest line number (or the line number called by RUN
). Statements on a line are executed from left to right. When all statements on a line are finished, execution moves to the next lowest line number, and so on until no line numbers are left. Control flow statements can be used to modify this normal flow of executon.
The END
and STOP
statements serve in a program to stop its execution and return to direct mode. When STOP
is used, a Break
message is printed. From direct mode, CONT
can be executed to resume the program where it was stopped. While END
seems intended to terminate the program, it does not preclude the user from resuming it with CONT
.
Unconditional jumps can be made with GOTO
. The program flow will continue at the line number indicated in the GOTO
statement. Due to the SE Basic IV language's lack of sophisticated looping, branching and breaking constructs, unconditional jumps are essential and used frequently.
The GOSUB
statement jumps to a subroutine. Similar to GOTO
, this is an unconditional jump; however, the location of the call is stored and the program will continue its flow there after the subroutine terminates with a RETURN
statement. Subroutines are somewhat like procedures in that they allow chunks of code that perform a given task to be separated from the main body of the program, but they do not have separate scope since all variables in SE Basic IV are global. They do not have return values. It is even possible to jump out of a subroutine to anywhere in the program by supplying the RETURN statement with a line number.
The ON
statement provides an alternative branching construct. An integer value is used to selects one of a list of line numbers, and execution is continued from there. It can be used with a GOTO
jump as wellas with a GOSUB
subroutine call.
ON
, GOTO
and GOSUB
can also be used from direct mode to start a program or subroutine without resetting variables.
The IF–THEN–ELSE
construct tests for a condition and execute different code branches based on its truth value. This is not a block construct; all code in the THEN
and ELSE
branches must fit on one line. For this reason, branching is often used in combination with GOTO
jumps. For example:
10 INPUT "How old are you"; AGE
20 IF AGE > 30 THEN 100
30 IF AGE < 30 THEN 200 ELSE PRINT "You are 30 years old."
40 END
100 PRINT "You are over 30."
110 END
200 PRINT "You are not yet 30."
210 END
The WHILE–WEND
looping construct repeats the block of code between WHILE
and WEND
as long as a given condition remains true.
The FOR–NEXT
construct repeats a block of code while a counter remains in a given range. The counter is set to a starting value at the first pass of the FOR statement and incremented by the STEP
value at each pass of NEXT
. For example:
10 FOR I=1 TO 10
20 PRINT STRING$(I, "*"); USING " [##]"; I
30 NEXT I
Looping constructs may be nested.
Control flow is also affected by event and error trapping.
Statement | Description |
---|---|
CONT | Continue interrupted program |
ELSE | Ignore the remainder of the line (standalone ELSE ) |
END | Stop execution of the program |
FOR | Start a for-loop |
GOSUB | Call a subroutine |
GOTO | Jump to another location in the program |
IF | Branch on a condition |
NEXT | Iterate a for-loop |
ON | Calculated jump or subroutine call |
RETURN | Return from subroutine |
STOP | Interrupt program execution |
WEND | Iterate a while-loop |
WHILE | Enter a while-loop |
Statement | Description |
---|---|
DIM | Allocate an array |
Function | Description |
---|---|
ASC | Character to ordinal value |
CHR$ | Ordinal value to character |
HEX$ | Integer to hexadecimal string representation |
VAL | String representation to numeric value |
[VAL$]](Language-reference#VAL-1) | String representation to string value. |
Function | Description |
---|---|
LEN | String length |
Statement | Description |
---|---|
CLS | Clear the screen |
COLOR | Set colour and palette values |
LOCATE | Set the position and shape of the text screen cursor |
PALETTE | Assign a colour to an attribute |
Print expressions to the screen |
Function | Description |
---|---|
SCREEN | Character or attribute at given location |
Statement | Description |
---|---|
Print expressions to the printer |
Statement | Description |
---|---|
INPUT | Retrieve user input on the console |
Function | Description |
---|---|
INKEY$ | Nonblocking read from keyboard |
INPUT$ | Blocking read from keyboard |
Statement | Description |
---|---|
KEY | Define a function-key macro |
Function | Description |
---|---|
ABS | Absolute value |
ATAN | Arctangent |
ACOS | Arccosine |
ASIN | Arcsine |
COS | Cosine |
EXP | Exponential |
INT | Floor |
LOG | Natural logarithm |
SIN | Sine |
SGN | Sign |
SQR | Square root |
TAN | Tangent |
Statement | Description |
---|---|
RANDOMIZE | Seed the random number generator |
Function | Description |
---|---|
RND | Pseudorandom number |
Statement | Description |
---|---|
CLOSE | Close a file |
INPUT | Read a variable from a file |
OPEN | Open a data file |
Function | Description |
---|---|
EOF | End of file |
LOC | Location in file |
LOF | Length of file |
SE Basic IV handles devices differently than Microsoft BASIC. A device is connected to a specific channel and one or more I/O streams can be connected to that channel. For example, the display is connected to channel S
and by default stream #2
is connected to that channel S
.
Device | Channel | Default stream |
---|---|---|
Keyboard | K | 1 |
Screen | S | 2 |
Statement | Description |
---|---|
SCREEN | Change the video mode |
Statement | Description |
---|---|
SOUND | Generate a tone |
Function | Description |
---|---|
MOUSE | Status of mouse |
STICK | Status of joystick |
In SE Basic IV, the DOS is integrated into BASIC and there is no SHELL
command.
Statement | Description |
---|---|
CHDIR | Change current directory. |
COPY | Make a copy of a file. |
FILES | List the files in the current directory. |
KILL | Delete a file on a disk device. |
MKDIR | Create a new directory. |
NAME | Rename a file on disk. |
RMDIR | Remove a directory. |
Statement | Description |
---|---|
ERROR | Raise an error |
ON ERROR | Define an error handler |
Statement | Description |
---|---|
DEF FN Define a new function |
Function | Description |
---|---|
FN | User-defined function |
Statement | Description |
---|---|
DATA | Define data to be used by the program |
READ | Retrieve a data entry |
RESTORE | Reset the data pointer |
Only selected memory ranges are accessible in SE Basic IV. There is read and write support for video memory, font RAM and selected locations of the low memory segment, including the keyboard buffer. Additionally, there is read and write support for variable, array and string memory. Writing into the program code is permitted but not recommended. All ports including keyboard input and video modes are supported.
Statement | Description |
---|---|
BLOAD | Load a binary file into memory |
BSAVE | Save a memory region to file |
CLEAR | Clears BASIC memory |
DEF SEG | Set the memory segment |
OUT | Write a byte to a machine port |
POKE | Write a byte to a memory location |
Function | Description |
---|---|
FRE | Amount of free memory |
INP | Byte at machine port |
PEEK | Byte at memory address |
Features that are planned but not yet implemented are missing links to the language reference.
SE Basic IV has direct access to all areas of memory and all devices. You can use machine-code subroutines to perform tasks for which it does not provide support. However, programs written for a different architecture, such as 8086, will not run.
It is not necessary, or possible, to define variable types. Like the 6502 versions of Microsoft BASIC, floating-point numbers are always stored in 40-bit MBF form. Unlike Microsoft BASIC, integers in the range -65536 to 65535 are always stored as integers (also in 40-bits).
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.