Cool AppleSoft BASIC trick I never thought of before

From: Vintage Computer GAWD! <foo_at_siconic.com>
Date: Tue May 16 23:03:22 2000

Stop me if you've heard this one before...

On the Apple ][, in AppleSoft BASIC, you can set what the start address
of your BASIC program will be in memory by poking it into location 103-104
($68-$69 hex).

The default is 2049 ($801): 103=1 and 104=8 ($68=1, $69=8).

QUESTION: Does anyone know why the default is $801 instead of $800? I
always wondered why that was. Anyway...

For various pratical reasons, usually to avoid over-running the beginning
of the first hi-res graphics page which began in memory at 8192 ($2000)
with variable data (which was always stored just after the end of the
BASIC program in memory), sometimes people would force their programs to
load at 16384 ($4000, which is also the beginning of the second hi-res
graphics page) or 24576 ($6000), or where ever.

It occured to me tonight as I was writing just such an application--the
Nerd Trivia Challenge management program for the VCF, which loads a
hi-resolution character generator at $1600, which would over-run my BASIC
code, which is therefore relocated to $4001--that two or more BASIC
programs could reside in memory at the same time! One would simply POKE
the beginning address into 103-104 and then LOAD the new program, and
repeat this for as many programs as is possible with the memory available.

As an experiment, I wrote two simple programs: one at $801 that simply
prints "PROGRAM 1!" and then sets the start of the program to $4001 by
POKEing a 64 into 104 then issues a RUN command, and another at $4001
that simply prints "PROGRAM 2!" and then sets the start of the
program to $801 by POKEing an 8 into 104 and issues a RUN.

I run either of the programs and I get an endlessly alternating display of
"PROGRAM 1!" and "PROGRAM 2!". In other words, it works! Cool.

The only problem here of course is that any variables in either program
will be quashed when the alternate program is run. However, there are
also pointers that point to the beginning of variable memory, and I'm sure
there would be a way to preserve these pointers so that individual
variables for either program stay intact between transitions. Something
worth exploring just for the hack value.

I never actually saw this in practice in all my years of Apple ][ hacking,
and believe me I snooped through a lot of code. Has anyone ever seen
this, and if so, for what purpose? I just thought of one example, which
was a Beagle Brothers product that let you have two programs in each 64K
bank of memory on a 128K Apple ][.

It seems to me this could be mutated into a sort of practical method of
multi-tasking BASIC programs.

Comments?

Sellam
Received on Tue May 16 2000 - 23:03:22 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:33:09 BST