STOS.BAS: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
 
== STOS .BAS file structure ==
 
== STOS .BAS file structure ==
   
Line 7: Line 6:
 
10 bytes Magic "Lionpoulos": STOS basic source
 
10 bytes Magic "Lionpoulos": STOS basic source
 
1 long length of source excluding the header
 
1 long length of source excluding the header
1 long offset to first memory bank form end of header
+
1 long offset to first memory bank from end of header
 
15 x
 
15 x
 
{
 
{
Line 19: Line 18:
 
</pre>
 
</pre>
 
--[[User:Nyh|Nyh]] 16:18, 10 July 2007 (EDT)
 
--[[User:Nyh|Nyh]] 16:18, 10 July 2007 (EDT)
 
 
 
   
 
== STOS source code format ==
 
== STOS source code format ==
Line 39: Line 35:
 
|-
 
|-
 
| x bytes || Tokenized code (length: line length - 4)
 
| x bytes || Tokenized code (length: line length - 4)
 
 
|-
 
|-
 
|}<br><br>
 
|}<br><br>
   
  +
The last line in the source code is always 4 0x00 bytes.
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.
 
 
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 [[STOS LOOKUP TABLES|lookup table]].<br>
 
Token bytes start from 0x80 onwards. If the token value <= 0x7F, use its ascii value. <br>
 
There are some special tokens, that may take up more than one byte:
 
There are some special tokens, that may take up more than one byte:
   
Line 57: Line 54:
 
| 0x8A<br><br><br> || Rem or '<br><br><br> || 1 byte: token (0x8A)<br>1 byte: unknown purpose<br>''x'' bytes: ASCII text, terminated by 0x00 end of line token
 
| 0x8A<br><br><br> || Rem or '<br><br><br> || 1 byte: token (0x8A)<br>1 byte: unknown purpose<br>''x'' bytes: ASCII text, terminated by 0x00 end of line token
 
|-
 
|-
| 0xA8<br>0xC0<br><br><br><br><br> || Extension instruction<br>Extension function<br><br><br><br> || 1 byte: token (0xA8 or 0xC0)<br>1 byte: extension index - extension A = 0x00, B = 0x01, … Z = 0x19<br>1 byte: lookup token - look this value up in the extensions lookup table<br>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.<br><br>
+
| 0xA8<br>0xC0<br><br><br><br><br> || Extension instruction<br>Extension function<br><br><br><br> || 1 byte: token (0xA8 or 0xC0)<br>1 byte: extension index - extension A = 0x00, B = 0x01, … Z = 0x19<br>1 byte: lookup token - look this value up in the [[STOS LOOKUP TABLES|extensions lookup table]]<br>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.<br><br>
 
|-
 
|-
 
| 0x98<br>0x99<br>0x9A<br>0x9B<br>0x9C<br>0x9D<br>0x9E<br>0x9F || Goto<br>Gosub<br>Then<br>Else<br>Restore<br>For<br>While<br>Repeat || 1 byte: token (0x98, 0x99, … 0x9F)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>4 bytes: unknown purpose<br><br><br><br><br><br>
 
| 0x98<br>0x99<br>0x9A<br>0x9B<br>0x9C<br>0x9D<br>0x9E<br>0x9F || Goto<br>Gosub<br>Then<br>Else<br>Restore<br>For<br>While<br>Repeat || 1 byte: token (0x98, 0x99, … 0x9F)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>4 bytes: unknown purpose<br><br><br><br><br><br>
 
|-
 
|-
| 0xA0<br>0xB8<br><br> || Extended instruction<br>Extended function || 1 byte: token (0xA0 or 0xB8)<br>1 byte: another token, to lookup in either the extended instructions table or extended functions table<br>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?
+
| 0xA0<br>0xB8<br><br> || Extended instruction<br>Extended function || 1 byte: token (0xA0 or 0xB8)<br>1 byte: another token, to lookup in either the extended instructions table or extended functions [[STOS LOOKUP TABLES|lookup table]]<br>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<br><br><br><br><br> || Variable name<br><br><br><br><br> || 1 byte: token (0xFA)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 byte: first 3 bits unknown purpose, remaining 5 bits, length of variable name<br>3 bytes: unknown purpose<br>''x'' bytes: ASCII variable name
+
| 0xFA<br><br><br><br><br> || Variable name<br><br><br><br><br> || 1 byte: token (0xFA)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 byte: 1st bit set if var is a string, 2nd bit if var is a float, 3rd bit set if var is an array, remaining 5 bits, length of variable name<br>3 bytes: unknown purpose<br>''x'' bytes: ASCII variable name, including any '$' or '#' postfix.
  +
|-
  +
| 0xFB<br> || Integer (binary) || ?
 
|-
 
|-
 
| 0xFC<br><br><br><br><br> || String literal<br><br><br><br><br> || 1 byte: token (0xFC)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>2 bytes: unknown purpose<br>1 word: string length<br>''x'' bytes: ASCII string value
 
| 0xFC<br><br><br><br><br> || String literal<br><br><br><br><br> || 1 byte: token (0xFC)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>2 bytes: unknown purpose<br>1 word: string length<br>''x'' bytes: ASCII string value
  +
|-
  +
| 0xFD<br> || Integer (hexadecimal) || ?
 
|-
 
|-
 
| 0xFE<br><br><br> || Integer<br><br><br> || 1 byte: token (0xFE)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 word: integer value
 
| 0xFE<br><br><br> || Integer<br><br><br> || 1 byte: token (0xFE)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 word: integer value
 
|-
 
|-
| 0xFF<br><br><br><br><br> || Floating point number<br><br><br><br> || 1 byte: token (0xFE)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 word: number value - 1st 24 bits are the mantissa, 25th bit is the sign, last 7 bits are the exponent<br>4 bytes: unknown purpose<br>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.
+
| 0xFF<br><br><br><br><br> || Floating point number<br><br><br><br> || 1 byte: token (0xFE)<br>0 or 1 byte: padding to make the next byte appear at an even position<br>1 word: number value - 1st 24 bits are the mantissa, 25th bit is the sign, last 7 bits are the exponent<br>4 bytes: unknown purpose<br>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. Accurate to 5 decimal places.
 
|-
 
|-
 
|}
 
|}
Line 76: Line 77:
   
 
--[[User:Darklight|Darklight]] 20:54, 2 September 2007 (EDT)
 
--[[User:Darklight|Darklight]] 20:54, 2 September 2007 (EDT)
  +
  +
[[Category:STOS BASIC]]
  +
[[Category:Data Formats]]

Latest revision as of 06:48, 20 January 2017

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 from 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)



The last line in the source code is always 4 0x00 bytes.

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 <= 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 lookup 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: 1st bit set if var is a string, 2nd bit if var is a float, 3rd bit set if var is an array, remaining 5 bits, length of variable name
3 bytes: unknown purpose
x bytes: ASCII variable name, including any '$' or '#' postfix.
0xFB
Integer (binary) ?
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
0xFD
Integer (hexadecimal) ?
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. Accurate to 5 decimal places.


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