AMOS BASIC tokenized file
Dan Tobias (Talk | contribs) (→Links and references) |
(add.w instead of add.l) |
||
(2 intermediate revisions by one user not shown) | |||
Line 288: | Line 288: | ||
*line++ ^= (key >> 8) & 0xFF; | *line++ ^= (key >> 8) & 0xFF; | ||
*line++ ^= key & 0xFF; | *line++ ^= key & 0xFF; | ||
− | key | + | key = (key & 0xFFFF0000) | ((key + key2) & 0xFFFF); |
− | key2 | + | key2 = (key2 + key3) & 0xFFFF; |
key = (key >> 1) | (key << 31); /* rotate right one bit */ | key = (key >> 1) | (key << 31); /* rotate right one bit */ | ||
} | } | ||
Line 314: | Line 314: | ||
== Sample files == | == Sample files == | ||
* http://cd.textfiles.com/amospd/SourceCode/ | * http://cd.textfiles.com/amospd/SourceCode/ | ||
− | * | + | * {{DexvertSamples|archive/amosSrc}} |
== Links and references == | == Links and references == |
Latest revision as of 22:37, 31 October 2024
AMOS BASIC is a family of BASIC dialects for the Amiga computer. They were written by François Lionet, who also wrote AMOS's predecessor, STOS BASIC for the Atari ST (see STOS memory bank).
There are several versions of AMOS published: AMOS The Creator, Easy AMOS and AMOS Professional.
AMOS has its own integrated development environment, and it uses its own custom file formats for everything, from source code to graphics and sound.
Contents |
[edit] Overview
AMOS is an interpreted BASIC dialect where code is edited and run in an integrated development environment. Every time the programmer finishes editing a line of code, it is immediately parsed into tokens. For example, typing procedure foobar
and pressing the return key will change the line into Procedure FOOBAR
.
Before a program can run, it will be tested to ensure it is free of syntax errors. Source code can be saved even if it is untested or fails testing, but AMOS includes a tested flag in the saved file. This is used by external software, for example the AMOS Compiler will refuse to compile an untested source code file.
[edit] Extensions
AMOS tokens are split between instructions in the core language and instructions in extensions.
Extensions are external files, written in 68000 assembler, which begin with a token table listing all the instructions they add to the language.
Each extension is intended to be loaded into a specific slot. AMOS has 25 slots for extensions. The configuration of extensions and their slots are saved in AMOS's global config file.
To load other people's source code, AMOS needs to be configured with the same versions of the same extensions that they used, in the same slots.
[edit] Banks
In order to work with multimedia such as pictures and music, AMOS has the concept of a bank or memory bank (see AMOS Memory Bank#Disambiguation for a note about terminology). An AMOS program can have up to 15 banks. For example, you can load several pieces of music into different banks, and then identify which one you want to play by a number: Track Play 5
will play music in bank 5. Or you could load a packed picture into bank 4 and say Unpack 4 to 0
, which will unpack the picture onto screen 0.
While you can load anything into any bank, some instructions can only take their data from specific bank numbers. Bank 1 is used for Sprites, which are controlled with instructions beginning Sprite
or Bob
. Bank 2 is for Icons, which are controlled with instructions beginning Icon
. Bank 3 is used for music in AMOS's native music format.
If banks are in use while saving source code, the contents of the banks are included in the saved source code. This makes it easy to bundle code with the data it works on. The exception to this rule is banks created using the Reserve As Work
instruction.
[edit] AMOS source code
All multi-byte integer values are in big-endian (Motorola) format.
AMOS source code is stored in a file with the extension .AMOS. It has the following structure:
Section | Length | |
---|---|---|
Header identifying which version of AMOS saved the file
|
16 bytes | |
Length in bytes of tokenized BASIC code to follow | 4 bytes | |
Tokenized BASIC code | varies | |
AMOS AmBs segment | ASCII identifier "AmBs" | 4 bytes |
Count of AMOS banks to follow (0–16) | 2 bytes | |
AMOS banks. Each bank's length must be individually determined. | varies |
[edit] Tokenised BASIC code
Tokenised BASIC code is a sequence of tokenised lines. Each tokenised line has the following format:
Field | Length |
---|---|
Length of this line in words (2 bytes), including this byte. To get the length of the line in bytes, double this value | 1 byte |
Indent level of this line. Prefix indent level + 1 spaces at the beginning of the line, or no spaces if the value is less than 2 | 1 byte |
Sequence of tokens. Each token is at least two bytes, and all tokens are rounded to to a multiple of two bytes. Each token is individually sized. The tokens always end with a compulsory null token | varies |
Some tokens have special size rules, but most are exactly 2 bytes in size.
Each token starts with a signed 16-bit number. Token values between 0x0000 and 0x004E have special printing and size rules, all other tokens are a signed offset into AMOS's internal token table. The instruction name in the internal token table is what should be printed.
[edit] Specially printed tokens
Token | Type | Interpretation |
---|---|---|
0x0000 | null token | Marks the end of line. Always 2 bytes long. |
0x0006 | Variable reference, e.g. Print XYZ
|
|
0x000C | Label, e.g. XYZ: or 190 at the start of a line
| |
0x0012 | Procedure call reference, e.g. XYZ["hello"]
| |
0x0018 | Label reference, e.g. Goto XYZ
| |
0x0026 | String with double quotes, e.g. "XYZ"
|
|
0x002E | String with single quotes, e.g. 'XYZ'
| |
0x001E | Binary integer value, e.g. %100101
|
|
0x0036 | Hexidecimal integer value, e.g. $80FAA010
| |
0x003E | Decimal integer value, e.g. 1234567890
| |
0x0046 | Floating point value, e.g. 3.1452
|
An exponent of 0 means 0.0, regardless of mantissa. Each set bit in the mantissa has the value 2m+e-88 where m is from 23 (MSB) to 0 (LSB) and e is the exponent |
0x2B6A | Double-precision float, e.g. 3.1415926543
|
An exponent of 0 means 0.0, regardless of mantissa. Each set bit in the mantissa has the value 2m+e-1074 where m is from 51 (implicit MSB) to 0 (LSB) and e is the exponent |
0x004E | Extension instruction |
|
[edit] Specially sized tokens
Token | Type | Interpretation |
---|---|---|
0x064A | Rem
|
The string is null terminated and its length is rounded up to a multiple of two. The string should be printed after the remark token. |
0x0652 | '
| |
0x023C | For
|
|
0x0250 | Repeat
| |
0x0268 | While
| |
0x027E | Do
| |
0x02BE | If
| |
0x02D0 | Else
| |
0x0404 | Data
| |
0x25A4 | Else If
| |
0x0290 | Exit If
|
|
0x029E | Exit
| |
0x0316 | On
| |
0x0376 | Procedure |
|
0x2A40 | Equ
|
|
0x2A40 | Lvo
| |
0x2A54 | Struc
| |
0x2A64 | Struct
|
[edit] Encrypted procedures
If you should find a procedure (0x0376) token with the "is encrypted" bit set, run this C function on the code and it will decrypt the contents of the procedure.
/* read 16-bit big-endian word from unsigned char[] */ #define amos_deek(a) ((((a)[0])<<8)|((a)[1])) /* read 32-bit big-endian word from unsigned char[] */ #define amos_leek(a) ((((a)[0])<<24)|(((a)[1])<<16)|(((a)[2])<<8)|((a)[3])) void AMOS_decrypt_procedure(unsigned char *src) { unsigned char *line, *next, *endline; unsigned int key, key2, key3, size; /* src should be a pointer to a line with the PROCEDURE token on it */ if (amos_deek(&src[2]) != 0x0376) return; /* do not operate on compiled procedures */ if (src[10] & 0x10) return; size = amos_leek(&src[4]); line = next = &src[src[0] * 2]; /* the line after PROCEDURE */ endline = &src[size + 8 + 6]; /* the start of the line after END PROC */ /* initialise keys */ key = (size << 8) | src[11]; key2 = 1; key3 = amos_deek(&src[8]); while (line < endline) { line = next; next = &line[line[0] * 2]; for (line += 4; line < next;) { *line++ ^= (key >> 8) & 0xFF; *line++ ^= key & 0xFF; key = (key & 0xFFFF0000) | ((key + key2) & 0xFFFF); key2 = (key2 + key3) & 0xFFFF; key = (key >> 1) | (key << 31); /* rotate right one bit */ } } src[10] ^= 0x20; /* toggle "is encrypted" bit */ }
[edit] AMOS Banks
AMOS banks can be found either included with AMOS source code, saved individually on disk, where they typically have the file extension .ABK.
AMOS allows for 15 banks in an program. Each bank can be located in "chip" memory, which is accessible to the Amiga's custom graphics and sound processors, or it can be located in "fast" memory, which is only accessible to the CPU.
Banks are identified by their first four bytes. They are either Sprite/Icon banks (using the ASCII identifier AmSp or AmIc), or they are "normal" memory banks, which covers all other possible bank formats (using the identifier AmBk).
[edit] AMOS Sprite/Icon Bank format
Refer to AMOS Sprite Bank. See also AMOS Icon Bank.
[edit] AMOS Memory Bank format
Refer to the main article: AMOS Memory Bank.