STOS.BAS: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
(Token code explanation)
Line 32: Line 32:
 
The source code is a stream of tokenized basic lines. Each line of STOS code equates to:
 
The source code is a stream of tokenized basic lines. Each line of STOS code equates to:
   
  +
{| border="1" class="wikitable" style="text-align:left"
1/2 word: The length of the line in bytes, including this value and the line number
 
  +
|-
1/2 word: The line number
 
 
| 1/2 word || The length of the line in bytes, including this value and the line number
x bytes: Tokenized code (length: line length - 4)
 
  +
|-
 
| 1/2 word || The line number
  +
|-
 
| x bytes || Tokenized code (length: line length - 4)
  +
  +
|-
  +
|}<br><br>
   
 
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.
 
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.
Line 40: Line 47:
 
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:
   
  +
{| border="1" class="wikitable" style="text-align:left"
Value Meaning Notes
 
  +
|-
0x00 Enf of line marker 1 byte: token (0x00)
 
  +
! style="background:#FFE3BC;" | Value
0 or 1 byte: padding to make the next byte appear at an even position
 
  +
! style="background:#FFDEE7;" | Command
 
  +
! style="background:#B4C9CE;" | Notes
0x8A Rem or ' 1 byte: token (0x8A)
 
  +
|-
1 byte: unknown purpose
 
 
| 0x00<br><br> || End of line marker<br><br> || 1 byte: token (0x00)<br>0 or 1 byte: padding to make the next byte appear at an even position
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 Extension instruction 1 byte: token (0xA8 or 0xC0)
 
  +
|-
0xC0 Extension function 1 byte: extension index - extension A = 0x00, B = 0x01, … Z = 0x19
 
 
| 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>
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<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 Goto 1 byte: token (0x98, 0x99, … 0x9F)
 
 
| 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?
0x99 Gosub 0 or 1 byte: padding to make the next byte appear at an even position
 
  +
|-
0x9A Then 4 bytes: unknown purpose
 
  +
| 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
0x9B Else
 
  +
|-
0x9C Restore
 
  +
| 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
0x9D For
 
  +
|-
0x9E While
 
 
| 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
0x9F Repeat
 
  +
|-
 
  +
| 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.
0xA0 Extended instruction 1 byte: token (0xA0 or 0xB8)
 
  +
|-
0xB8 Extended function 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.
 
   
 
--[[User:Darklight|Darklight]] 20:54, 2 September 2007 (EDT)
 
--[[User:Darklight|Darklight]] 20:54, 2 September 2007 (EDT)

Revision as of 02:29, 3 September 2007

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)