** N-Progs **

A set of ML programs for the Commodore 128 that allow multiple
BASIC programs to exist in memory at the same time.

There are 3 versions:

Name		Max prg.size	Max var.size
--------------------------------------------
2-progs		27.6K/111 blks	31.3K
2g-progs	23.1K/ 93 blks	31.3K
3-progs		18.2K/ 73 blks	20.9K

The first character of the filename (a number) indicates the
number of programs you can have in memory at once (2 or 3).
Only the G version should be used with programs that use
the VIC bitmap screen (this includes the SPRDEF editor).

There are only 2 steps needed to use N-Progs.

First, load and start the version of your choice with:

BLOAD"N-PROGS",B0	(where N is 2, 2G, or 3)
BANK 0:SYS 65168	(J FE90 in Monitor)

This will setup BASIC in 'memory space' zero (0).
NOTE: This will erase any BASIC program in memory!

Second, switch memory spaces at anytime with:

BANK 0:SYS 65024,n	(J FE00 in Monitor with .A = n)

where n is the 'memory space' you want to switch to:
	0 or 1		(version 2 or 2g)
	0, 1, or 2	(version 3)

Note: after the switch, BASIC will be configured to BANK 15.

You can LOAD, edit, RUN, STOP, CONT, SAVE, a program in a
memory space independant of programs in other memory spaces.

--------------------------
How it works
--------------------------
Each program has its own area of Bank 0 for program storage.
This includes the program along with any embedded DATA for
DEFined functions.

Each program has its own area of Bank 1 for variables.
This includes all variables, arrays, and strings.

Each program has its own BASIC stack which holds information
about FOR/NEXT, DO/LOOP, and GOSUB/RETURN.  This is stored
in a 512-byte block near the top of Bank 0 when a program is
inactive.  The program of the current memory space has this
information copied to the fixed location $800~$9ff in Bank 0.

Each program has pointers to memory limits, DATA, current line#,
trap line#, error line#, error#, and PRINT USING characters
(aka PUDEF) stored in the $FD00 block of memory when inactive.
The program of the current memory space has this information
copied into special BASIC locations in zero page and page 18 ($12xx).

Everything else is shared between all programs.  This includes:
	Open files (managed mainly by KERNAL)
	Text / graphic colors
	Cursor postion and Windows
	Function key strings
	Sprites (both images and movement)
	Sound, Envelope, Volume, etc.

The reserved variables ST and TI are actually copied from the
KERNAL so they are also shared.

BUT, the disk error status, DS$ is written to Bank 1 like normal
variables so it is NOT shared (strictly speaking).

To be compatible with other utilities, the area $1300~$1bff is NOT
used by this program.  Neither is the popular zero page memory $fa~$ff.

The program temporarily uses $50~53 when switching memory spaces.
Data is stored from $f700 (version 3) or $f900 (version 2,2g)
up to $fdff. The ML program itself lies at $fe00~$fefd.  The current
memory space number is stored at $fefe.

----------------------
Known problems
----------------------
During a TRAP, the CPU stack is saved and manipulated.  This is
different from the BASIC stack.  TRAP can be used in programs,
but your program must NOT switch to another program during the TRAP
routine.  The TRAP ends and the CPU stack is fixed when the RESUME
command is executed.  Program switching can occur again after RESUME.

SPRITES and the LightPen can cause collissions at any time.  It is
recommended to not use COLLISSION (not tested). BUMP should be okay.

Switching between running programs may fail depending on the types
of 'nesting' in use on the stack.  My limited tests show this:

FOR/NEXT(p0) with DO/LOOP(p1) is okay
FOR/NEXT(p0) with GOSUB/RETURN(p1) is okay
DO/LOOP(p0) with GOSUB/RETURN(p1) will crash BASIC!!!!
FOR/NEXT(p0) with DO/FOR/GOSUB/RETURN/NEXT/LOOP(p1) is okay

This is rather strange!  I've had no problems with one running
program switching to another memory space in immediate mode
(and switching back to the running program tests okay too).
To be safe, it is recommended you not switch spaces
between two (or more) running programs.