STOS.BAS

From Atari Wiki
Jump to navigation Jump to search

STOS .BAS file structure

BAS_HEADER
{
 10 bytes  Magic "Lionpoulos": STOS basic source
  1 long   length of source excluding the header
  1 long   offset to first memory bank form end of header
15 x
{
  1 byte   bank type
  3 byte   bank length
}
___+
 78 byte   header size
}
 ?? byte  source code

--Nyh 16:18, 10 July 2007 (EDT)



STOS source code format

Bear in mind a Motorola 68000 based system uses big endian format, and 1 word is 4 bytes (32 bits), 1/2 word is 2 bytes (16 bits). To interpret on an Intel / PC based system, you will need to reverse the order of the bytes in each word / 1/2 word.

Credit should go to the writer of Amos file formats page, as I found it very useful, especially for the floating point translation. Also I got the lookup table information from the STOS source code - thanks to lp (Lonny) from the forum for that suggestion.

The source code is a stream of tokenized basic lines. Each line of STOS code equates to:

1/2 word The length of the line in bytes, including this value and the line number
1/2 word The line number
x bytes Tokenized code (length: line length - 4)



Most tokens are one byte, and represents one command or function. To find the name of the command or function, look up the byte value in the lookup table. Token bytes start from 0x80 onwards. If the token value is 0x7F, use its ascii value. There are some special tokens, that may take up more than one byte:

Value Command Notes
0x00

End of line marker

1 byte: token (0x00)
0 or 1 byte: padding to make the next byte appear at an even position
0x8A


Rem or '


1 byte: token (0x8A)
1 byte: unknown purpose
x bytes: ASCII text, terminated by 0x00 end of line token
0xA8
0xC0




Extension instruction
Extension function



1 byte: token (0xA8 or 0xC0)
1 byte: extension index - extension A = 0x00, B = 0x01, … Z = 0x19
1 byte: lookup token - look this value up in the extensions lookup table
Note: The extension index is relevant to the extension configuration at the time of saving the .BAS file. So for a .BAS file that contains extension commands to be correctly interpreted when loading, the same extensions need to be present at the same letters.

0x98
0x99
0x9A
0x9B
0x9C
0x9D
0x9E
0x9F
Goto
Gosub
Then
Else
Restore
For
While
Repeat
1 byte: token (0x98, 0x99, … 0x9F)
0 or 1 byte: padding to make the next byte appear at an even position
4 bytes: unknown purpose





0xA0
0xB8

Extended instruction
Extended function
1 byte: token (0xA0 or 0xB8)
1 byte: another token, to lookup in either the extended instructions table or extended functions table
Note: These are nothing to do with extensions, and I guess were added when the programmers realised the wouldn’t fit all the instructions into values 0x80 - 0xFF?
0xFA




Variable name




1 byte: token (0xFA)
0 or 1 byte: padding to make the next byte appear at an even position
1 byte: first 3 bits unknown purpose, remaining 5 bits, length of variable name
3 bytes: unknown purpose
x bytes: ASCII variable name
0xFC




String literal




1 byte: token (0xFC)
0 or 1 byte: padding to make the next byte appear at an even position
2 bytes: unknown purpose
1 word: string length
x bytes: ASCII string value
0xFE


Integer


1 byte: token (0xFE)
0 or 1 byte: padding to make the next byte appear at an even position
1 word: integer value
0xFF




Floating point number



1 byte: token (0xFE)
0 or 1 byte: padding to make the next byte appear at an even position
1 word: number value - 1st 24 bits are the mantissa, 25th bit is the sign, last 7 bits are the exponent
4 bytes: unknown purpose
Note: to convert to a readable format, each bit of the mantissa = 2 ^ (bit_position + exponent - 88.0). Add up the values indicated by each bit in the mantissa.


--Darklight 20:54, 2 September 2007 (EDT)