This is an old revision of the document!
Table of Contents
BASIC file format
Header
BASIC sources aren't stored in plain ASCII. To allow faster loading and parsing, they are stored in bytecode format. The file is in standard DECB format, with a single block of type 0xFF. Since internal structures use absolute addresses, it is important to keep that header to know the loading address of the BASIC program.
Offset | Description |
---|---|
0 | File type = 0xFF |
1 | File size |
3 | Load address |
Lines
A BASIC program is a packed linked list of program lines.
Offset | Description |
---|---|
0 | Address of next line |
2 | Line number in hex |
4 | NULL-terminated line data |
The end of the listing is marked with a NULL next line pointer.
The line data is a mix of tokens and ASCII characters. The tokens are used to encode all the keywords and functions, but everything else (numbers, strings, comments) is stored in ASCII.
Keyword and token list
Keyword | Description |
---|---|
? | Alias to PRINT |
' | Alias to REM |
ATTRB | Character attributes |
BOX (x1,y1)-(x2,y2) | Draws a rectangle (the top left pixel is (0,0) |
BOXF (x1,y1)-(x2,y2),color | Fills a rectangle with the given color (optional, if not given use the current pen color). Negative colors lead to filling with the requested color as the background one. |
CLS | Clear screen |
COLOR foreground,background | Change pen colors (parameters are optional) |
CONSOLE | |
DELETE | |
END | Ends program execution |
FOR v=s TO e STEP n | FOR loop, incrementing v by n each time until it reaches e. The STEP is optional (default is 1) and can be negative. |
GOTO line | Jump to program line |
IF a THEN statement ELSE statement | Conditions (the statement can be just a line number) |
INPUT “message”;variable1,variable2 | Set variables to user-entered values (comma separated). A ? is printed after the message and before reading the values from the user. |
LINE (x1,y1)-(x2,y2) | Draws a line (first point is optional, current cursor position is used: LINE -(x2,y2) ) |
LIST line | List the program in memory (parameter is optional, if missing the whole program is listed) |
LOCATE x,y | Move the cursor |
NEW | New program, remove current one from memory |
NEXT v | Closes FOR loop. |
PLAY s$ | Plays music. The string is made of notes DO,RE,MI,FA,SO,LA,SI (with # and b modifiers), octave changes (O1-O5), note duration changes (L1-L96), silences (P), tempo changes (T1-T256), attack settings (A0-A255). Spaces are ignored and can be used for readability |
PRINT value | Prints a value (if the value is suffixed with a ; insert a tabulation after it. else goes to next line) |
PRINT USING | |
PSET(x,y) | Set a pixel |
REM | Comments (REMark). Anything following this on the line is ignored. |
RUN | run the program |
SCREEN foreground,background,border | Changecolors for whole screen |
Function | Description |
---|---|
COS(v) | Cosine |
INT(v) | Integer part of value |
INSTR | |
LEFT$(s$,n) | Get a substring of the N first chars of S |
LEN(s$) | Get length of string |
MID$ | |
RIGHT$(s$,n) | Get a substring of the N last chars of S |
RND | Random value between 0 and 1 |
SIN(v) | Sine |
STR$ | |
VAL |
Operator | Description |
---|---|
+ | Addition, string concatenation |
- | Substraction |
* | Multiplication |
/ | Division |
MOD | Modulo |
@ | Integer division |
= | Assignment |
^ | Exponent |
Condition | Description |
---|---|
= | Equality |
Tips and tricks
The PLAY command can be used for accurate delays.