[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Moving BASIC around in memory (Re: DRAW & XDRAW... How to use)



On Wed, 05 Jan 2000 14:49:05 -0800, jh82
<webmasterNOweSPAM@jh82.i-p.com.invalid> wrote:

>Dave,
>
>I know you said it doesn't matter where you put the shape table, but
>what address would be the best place to start?  I know that if I just
>start poking numbers, I 'm going to crash my apple. (I've done it
>before).


You can "open up" as much free space as you need right
where BASIC normally loads your BASIC program.

Bytes 103 and 104 store where DOS will load and run a
BASIC program. By creating a "BASIC Preloader" you can
change those locations and THEN load your regular BASIC
code into that new location. Here's a short little
program which will create empty space in memory from
2048 to 4047:

10 NEED = 2000
20 IF NEED < 153 THEN PRINT "SIZE TOO SMALL!": END
30 MV = 2049 + NEED
40 P4 = INT (MV/256)
50 P3 = MV - P4*256
60 POKE MV-1, 0 : POKE 103, P3: POKE 104, P4
70 PRINT CHR$(4)"RUN PROGRAM.2"

NOTE: You must create a minimum of 153 bytes of free
      space using this method or you will trash this
      program.

      If you only need 153 bytes or less, the region
      from $300-$3CF would be a good choice and you
      can just skip this BASIC-mover method..

-----------------------------------------------------
Here is an explanation of what is going on there.....

Preloader- Move BASIC to free up memory

How much free memory do you need? Put the value here:

100 NEED = 2000

Normal load point for BASIC is 2049

So we need to add how much you need to 2049 and then
convert it to base-256 to POKE it into the memory
locations 103 and 104...

110 MV = 2049 + NEED
120 P4 = INT (MV/256)
130 P3 = MV - P4*256

Okay, a BASIC program must be preceded by a zero.
This is why it starts at 2049 rather than 2048.
So the new load location must be preceded by a zero.

Then we POKE those two new values into memory, which
changes where BASIC excepts to find a program, and 
then immediately load the 'real' BASIC program
which needs the freed-up memory..

140 POKE MV-1, 0 : POKE 103, P3: POKE 104, P4
150 PRINT CHR$(4)"RUN PROGRAM.2"

The warning about a 153 byte minimum has to do with
the fact that this program itself is about 153 bytes
in size. If you use a value less than 153, you'll be
overwriting this code and it'll likely crash.


----------------------------------------------------

Note that this moving of BASIC won't automagically
reset itself. If you type NEW, it'll still be a new
program starting at your modified location in memory.
This could cause trouble for an unsuspecting user of
your program if your program exits to BASIC and
leaves BASIC loading in a nonstandard location.

If this is a program you intend to distribute, it
would be wise to end the program with this line to
reset things to normal. Warning, this line will
erase your program if you've been programming and
haven't saved it before this line is run...

POKE 2048,0: POKE 103,1: POKE 104,8: NEW


--------------------------------------------------------

If you need the maximum available space for other stuff
without BASIC intruding, you can do some cute tricks,
such as moving BASIC -above- the hires graphics regions,
to $6000. This gives you the following free memory areas
in addition to your BASIC code areas:

 $0800 to $0BFF = 1k for text page 2 
 $0C00 to $1FFF = 5k for shapetables or machine language
 $2000 to $3FFF = 8k for hires page 1
 $4000 to $5FFF = 8k for hires page 2 
 $6000 to HIMEM = about 13k for BASIC

To do this...

POKE 24576,0: POKE 103,1: POKE 104,96: ?CHR$(4)"LOAD PART2"

Just remember that both BASIC and its variables sit inside
that 13k block, which may put some serious space constraints
on your programming. More code or less variables? 

-Mr. Boffo

Email: mister_boffo@hotmail.com