Personal Computer News


Amstrad Basic Storage Structure

 
Published in Personal Computer News #091

Amstrad Basic Storage Structure

Basic programs start at address &170 and each line carries a four byte prefix. The first wo bytes are a count of the number of bytes in the line, stored in LSB/MSB format (i.e. least significant byte first), and bytes three and four are the binary representation of the line number, also in LSB/MSB format.

The text of the line follows and each line is terminated by a zero byte. The entire program is terminated by two null bytes, corresponding to a null line length.

Like most Basic implementations, the language keywords are not stored letter by letter. Instead a one or two byte compression code is used. For example, the keyword AFTER is not stored as five letters, but as the single code value 128. The code tokens form two series, one byte codes comprising values from 128 to 254, and two byte codes in which a byte with value 255 is immediately followed by a value from 1 to 127.

Not all the code values seem to be assigned - it appears that Locomotive could have made its rich dialect of Basic even more so. Of the single byte tokens, codes 128 to 220 are all assigned, but 221 to 226, 232, 233, and 238 to 249 appear to be free.

Similarly, the two byte keywords occur from 1 to 29, from 64 to 72 and from 113 to 127 (with 114 and 123 missing).

The remaining values are unused. To see the codes in action, try this routine:

   10 REM ***************
   20 INPUT J
   30 POKE &178,J:POKE &179,32
   40 IF J=255 THEN INPUT J:POKE &179,J:POKE &17A,32
   50 LIST 10

The stars in line 10 are significant. Run the program, and answer the input prompts with values between 128 and 254 for one byte keywords or 255 (value between 1 and 127) for a two byte keyword and you'll find a Basic keyword has been generated among the asterisks in line 10.

D. Bright
The Hague, Holland

D. Bright