<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 17 Nov 2006 18:15:38 -0000
From   : dl.harper@... (David Harper)
Subject: Memory map questions

gARetH baBB wrote:

>> Does anybody have documentation for the layout of BBC BASIC programs in
>> RAM? I'm really only interested in BASIC II as shipped with the
>> Electron, but any information would be gratefully accepted.
>
> You want the BASIC ROM User Guide. To summarise:
>
> 00 Line number MSB
> 01 Line number LSB
> 02 Length
> 03 data, terminated by CR
>
> MSB with high bit set is end of program.

Remember that the first byte is always &D (i.e. CR). It is up to you whether 
you regard the &D in each line as the first byte of the line following or 
the last byte of the line preceding.

I have always thought of it as each line beginning with 4 bytes before the 
data:
    0 - &D
    1 - Line number MSB
    2 - Line number LSB
    3 - Line length (in bytes)
One can then say that the end-of-program marker is &D followed by a 
top-bit-set byte.

The machine can skip through a program very quickly, starting with a &D, 
then looking for the next one "line-length" bytes later until it reaches the 
end. If one of these fails to be a &D, then you get a "Bad program" error.

As regards the data in each line, keywords are tokenized. Line numbers 
(following GOTO GOSUB etc) are encoded so that they always take up the same 
number of bytes, making rapid renumbering easy.

David Harper 



<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>