[comp.sys.cbm] Why LOAD"<filename>",8 doesn't always work on the C128!

daemon@rutgers.UUCP (04/14/87)

From: prindle@NADC

Hi,
I've just unraveled one of life's great mysteries.  Have you ever wondered why
some programs refuse to run properly on the Commodore 128 (in 128 mode) if you
first LOAD "<filename>",8 and then RUN?  Yet the same program runs ok if you
DLOAD "<filename>" and then RUN!  Two notable examples: MICROVT-128 and 
Paperback Writer 128/Pocket Writer 2.0.  Well, now I know the source of the
problem:

It seems that writers of ML programs for the 128 still use the three call
sequence - SETLFS, SETNAM, OPEN - to open a disk file or send a command to
the disk command channel.  However, though it is not terribly obvious from
any documentation, the proper sequence on the 128 must include a 4th Kernal
call like this - SETLFS, SETNAM, SETBNK, OPEN - where "SETBNK" is the Kernal
entry point at $FF68 (A must contain bank number for data to be loaded/saved,
and X must hold the bank number of the filename whose address is given in the
SETNAM call).  Failure to call SETBNK with X=0 when the filename or command
specified by the SETNAM call is indeed in bank 0 produces the erratic results.
Why, you ask?  Well it just so happens that LOAD "<filename>",8 leaves the
filename bank set to 1, while DLOAD "<filename>" leaves it set to 0! (The
currently selected filename bank is found in $C7).  Thus, running such a 
program after a LOAD "<filename>",8 makes it send filenames to the disk drive
from bank 1, not likely to be where the writer of the program had intended to
put the filename; thus the disk drive gets a syntax error or locks up or does
some other unpredictable thing.  The program behaves fine after DLOAD or BOOT
however.

The fact is that many BASIC commands leave the filename bank set to 1 (e.g.
a simple CLOSE 1).  The moral is to always use SETBNK, at least once during
initialization of an ML program, to establish where filenames to be used in
subsequent opens are located.  The temporary solution for programs that do
not do this is to use DLOAD instead of LOAD.

Of course, it would have been nice of Commodore to make the RUN command always
initialize $C7 to 0.

Sincerely,
Frank Prindle