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

Re: Applesoft commands



Warren Tustin (warren@col.hp.com) wrote:

(thanking Nathan snipped.  Good work, Nathan!)
:   I also was wondering about memory.  I stumbled on fre(x) to tell me how
:   much memory is available.  Does the - number mean (32768 - (-N))?  I
:   vaguely recall this from the days I helped someone else with a IIe and
:   assumed the IIc was the same.  Does a lot of the 128k get used by BASIC?
:   The IIc vintage is (255) in the 64447 location (I think that is the addr).

A couple of things here...
First of all, the formula for translating negative numbers under Applesoft
is n + 65536; for example, "PEEK (-16384)" is equal to "PEEK (49152)".  I
think the inclusion of this little trick was originally related to a
problem with Integer BASIC:  In a 64k machine, there are 65,536 memory
addresses, and in the Apple, the BASIC and Monitor ROM routines are in the
upper 16k (49152 [$C000] - 65536 ($FFFF]).  But Integer BASIC can only
handle numbers between -32767 and +32767.  So attempting to read the
keyboard using KB=PEEK(49152) (which works under Applesoft) will result in
*** >32767 ERROR
under Integer BASIC.  But if you subtract 65,536, you get a legal negative
number (-16384), and all of those ROM entry points in fact are located
between -16384 and 0.

I suppose that is far more than you ever wanted to know.  8-)

As for memory under Applesoft...Forget that you have a 128k machine. 
Where Applesoft is concerned, you have a 48k machine.  Sorry.  The memory
map (WARNING:  I'm doing this from memory!) is something like this:

$0000 - $00FF  Zero Page (system data)                
$0100 - $01FF  System Stack                           
$0200 - $02FF  Input buffer                           
$0300 - $03FF  Mostly free, also contains system and OS vectors
$0400 - $07FF  Text Page 1
$0800 - $0BFF  Text Page 2.  Applesoft programs start at $0801.
$0C00 - $1FFF  Free for Applesoft programs, etc.
$2000 - $3FFF  High-Resolution Graphics Page #1 (programs can sit here too)
$4000 - $5FFF  High-Resolution Graphics Page #2 (programs can sit here too)
$6000 - $9D00  Free
$9D00 - $BFFF  Used by DOS 3.3, or by BASIC.SYSTEM if you use ProDOS
$C000 - $CFFF  Hardware soft-switches
$D000 - $FFFF  Applesoft and Monitor ROM

There is the lower 48k plus ROM.  Applesoft programs start at $801, and
build up from there.  Be aware that variable storage starts just below DOS
(or BASIC.SYSTEM) and starts filling in so that the program and its
variables can meet near the middle.  You've discovered the FRE(0)
command...in addition to returning the amount of free memory, it also
forces a string garbage collection.  When you change the contents of a
string variable, the old string value is retained, and a new version of
the string is created in memory.  When the variable space starts to get
full, Applesoft will do a "garbage collection", moving the "valid" string
variables around, throwing out the "obsolete" ones.  This can bring a data
processing operation to a grinding halt for a while.  Forcing a garbage
collection in a string-intensive routine can slow things down a little,
but will also prevent things from getting REALLY slow.  Under ProDOS, you
can use PRINT CHR$(4);"FRE" to do the same thing, only faster.

Getting back to the memory map....I only covered 48k of RAM and 16k of
ROM.  What about the 16k RAM, known to Apple ][+ users as the "Language Card"?

$D000-$FFFF also exists in the Slot 0 peripheral card space.  Note that
the ][e does not have a Slot 0; that's because the 16k RAMcard that would
go there is built in to the motherboard.  By throwing a couple of soft
switches in the $C000-$CFFF area, the machine's ROM can be switched out
and replaced with RAM.  The problem with this is that the ROM space is
where the Applesoft interpreter lives, so as soon as you kick the switch,
Applesoft for all intents and purposes ceases to exist.  This is why
ProDOS users who want to use Applesoft have to use BASIC.SYSTEM as
well...ProDOS lives in this memory space, so BASIC.SYSTEM handles the
switching between main ROM and the "language card" RAM.  Under DOS 3.3,
that space is left alone, and is commonly used for the Integer BASIC
interpreter.  Or, for other useful programs...GPLE.LC lives up there; BIG
MAC/Merlin-8 can live up there...stuff like that.  There is even a way to
move DOS 3.3 into that space, though I know that's ancient history to most
of the people here.  8-)

Okay, so there is a full 64k of RAM.  What about the other 64k?

Well, the 6502 is an 8-bit microprocessor with the ability to address a
16-bit address.  That means the highest address available to the 6502 is
%11111111 11111111 or $FFFF or 65,535.  That's only 64k.

To handle the other 64k, another set of soft switches is used in the ][e
or //c to switch between the main bank and the auxiliary bank.  Which
means that from $0000-$BFFF, there are two banks of memory, and from
$D000-$FFFF there are three (ROM, Main RAM, and Auxiliary RAM).  Are you
as confused as I am yet?  Again, we have the bank-switching problem.  If
you are a program running in main memory, and you suddenly switch to
auxiliary memory, what happens?  You suddenly disappear!  So auxiliary
memory is something best left to assembly language, just like the upper
16k.  Although I think there is at least one Beagle Bros package that
allowed you to use the upper 64k like a second computer...by invoking a
hotkey or command, you could instantly switch between a program running in
main memory and a program running in auxiliary memory.  Neat idea, but I
never tried or played with it.

Have fun!  8-)

--Dave Althoff, ][.
  (long-time self-described Applesoft Ace)
-- 
    /-\      Celebrating the International Year of the Roller Coaster
   /XXX\      /X\     /X\_      _     /XX\_      _     _        _____  
  /XXXXX\    /XXX\  _/XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX