The .bas file format

BASin

The .bas file format

A .bas (BASin program) file contains a plain-text representation of a Spectrum BASIC program and variables. This is the preferred file format for programs developed in BASin.

The .bas format is an extension of the format used by zmakebas, a tool written by Russell Marks that converts plain-text BASIC programs into .tap files for loading into a Spectrum emulator.

Variables

A .bas file begins with an optional variables section, which describes the BASIC variables that were resident in memory when the program was saved.

Each variable declaration will take the form:

  • Var [v]:[Type] = [Value]

Where v is the variable name (a$, a etc). Type would be one of Num, Str, NumArray(), StrArray(), NumFOR. Strings would be Quote (") delimited, with normal BASIC quote-in-quote rules applied.

There are five different types of entry:

Numeric

Var name:Num=value

String

Var name$:Str="value"

Numeric array

Var name(dim1,dim2,. . .):NumArray=value1,value2,. . .

String array

Var name$(dim1,dim2,. . .):StrArray="value1","value2",. . .

Loop counter

Var name:NumFOR=current,limit,step,loop-line,loop-statement

Multi-dimensional arrays are stored in a linear fashion, so that all the elements of the first dimension precede all those of the second dimension, and so on.

For a loop counter variable, loop-line and loop-statement represent the statement immediately after the FOR statement, i.e. the one to which program flow will jump when the corresponding NEXT is encountered.

Auto-run line number

The variables section is followed by an optional Auto declaration, which specifies the line number at which the BASIC program starts running. This corresponds to the SAVE . . . LINE syntax, and takes the form:

Auto line-number

Program

The next part of the .bas file is the actual program listing. Keywords are stored as plain text (so e.g. PRINT is five letters), not the non-standard keyword tokens from the Spectrum character set.

If you have selected Break multi-statement lines on BASin's Files tab, any program line containing more than one statement is split across multiple lines in the file, one for each statement. This is indicated by a line ending with a \ backslash, e.g.

10 PRINT "this is the first statement":\
PRINT "this is the second statement"

Special characters

Spectrum BASIC supports some non-standard control characters (for colours and text formatting) and graphics characters. In .bas files, these special characters are represented by escape sequences, so that the files can be easily viewed and modified in a text editor. Escape sequences begin with a \ backslash.

The escape sequences for control characters are as follows:

\{in}

Ink colour n, where n is in the range 0 to 7.

\{pn}

Paper colour n, where n is in the range 0 to 7.

\{bn}

Bright n, where n is 0 or 1.

\{fn}

Flash n, where n is 0 or 1.

Note: Control character escape sequences can be combined, so that for instance \{i6p1f1} is equivalent to \{i6}\{p1}\{f1} - flashing yellow ink on blue paper.

The escape sequences for graphics characters are as follows (note the spaces!):

\  

The character.

\. 

The character.

\ '

The character.

\.'

The character.

\' 

The character.

\: 

The character.

\''

The character.

\:'

The character.

\ .

The character.

\..

The character.

\ :

The character.

\.:

The character.

\'.

The character.

\:.

The character.

\':

The character.

\::

The character.

\letter

A user-defined graphics character, where letter is in the range a to u.

Other escape sequences are as follows:

\@

The @ at symbol.

\\

The \ backslash symbol.

\`

The £ pound sterling symbol.

\#nnn

Any character, where nnn is a decimal number in the range 000 to 255.