these steps:
1. Calculate the total size needed for your machine language programs
and/or custom character set. (SIZE)
2. Get the "top of Basic memory", as instructed earlier. (TOBM)
3. Calculate new "top of Basic memory" (NTOBM): TOBM - (SIZE + 1).
4. Calculate low and high parts of the NTOBM:
HI = INT(NTOBM / 256)
LO = NTOBM - (HI * 256)
5. Set new "top of Basic memory":
POKE 55, LO
POKE 56, HI
CLR
Note! The CLR statement at the end of step 5 is essential. It sets a lot of
pointers used by Basic to the "top of Basic memory" and Basic will crash unless it
is executed after the POKEs.
Note! If you have a Plus/4 and want your program to be C16 compatible, then
instead of calculating from the real top (end) of memory (64768), calculate from
16374 instead.
ON THE OTHER SIDE
You can also move the start of the basic memory instead, but that is a bit more
difficult as the whole basic program then needs to be moved. You can alter the
start position of the basic memory this way:
POKE 44,x : POKE x*256,0 : NEW
...and the basic memory will then start at x*256. If x for example is 32, then the
basic memory will start at 32*256=8192. But as a NEW command is used, it is tricky
to do this at run time. It needs multi part loading, poking into the keyboard
buffer etc, or another trick is to have two basic programs in memory where one is
starting the other one... Complicated stuff... but on the expanded vic-20 this is
quite common as the vic chip only can address the first internal 5K and not the
expanded higher memory. But anyway, for us, it's much easier to move the end limit
of the memory instead, as described above... except for if you use the following
little trick on the Plus/4:
GRAPHIC1:GRAPHIC0
...Then (as described in the Basic 3.5 document under GRAPHIC), the whole basic
program is moved at runtime from 4097 to 16385 taking 12kb from the basic memory.
If you don't use the graphics, you can use this 12kb area for other things. And
even if you use the graphics, the 2kb area 4097-6143 is still unused and available
for other things. But this approach will give programs that NOT are compatible
with the C16! Well, as long as you don't use the extra 4097-6143 area and only the
10kb graphics area, then it's C16 compatible, but then you will only have 2kb left
for the basic...
FORMAT OF BASIC PROGRAMS IN MEMORY
Basic stores programs in memory in a special compressed format to conserve
memory. Conversion occures when you enter a new line in your Basic program:
each reserved word (PRINT, GOTO, INPUT... ) found in the line will be converted
to a single byte called a token and stored into the memory. When you list your
program, LIST command translates the tokens and displays them as the original
reserved words.
A Basic line has the following format in the memory:
{LON HIN} {LOL HIL} CONTENTS EOL|EOP
{LON HIN} is a 16-bit pointer to the start of the next Basic line. LON
contains the lower 8 bits of the address and HIN the upper 8 bits. In case of
last Basic line, {LON HIN} points to EOP.
{LOL HIL} is a 16-bit linenumber. LOL contains the lower 8 bits of the
linenumber and HIL the upper 8 bits.
CONTENTS is the contents of the Basic line. Line composes a mixture of tokens
and PET-ASCII characters: bytes with a value less than 128 are conventional
characters and bytes greater than or equal to 128 are tokens.
10
Comentarios a estos manuales