!lm12
!rm75
EXEC without END from Applesoft............Bob Sander-Cederlof

I have been working on a project with Lee Meador which requires a binary file to be loaded into the second $D000 bank of a 16K RAM card.  It is just a little tricky to do this!

You cannot just use a simple BLOAD, because you have to be sure the RAM card is selected and write-enabled.  You cannot do it from a running Applesoft program, or even as a direct command after the Applesoft prompt, because if the RAM card is enabled the Applesoft ROMs are not.  We wanted to do it from within the running Applesoft program.

The typical answer is to create an EXEC file with the commands to call the monitor, select the RAM card, BLOAD the file, reselect the motherboard ROMs, and bounce back to Applesoft.  For example:

!lm+5
CALL-151               call Apple monitor
C089 C089              write-enable RAM with 2nd bank
F800<F800.FFFFM        copy of monitor in RAM card
BLOAD B.BOBANDLEE      load the file
C081                   back to Applesoft ROMs
3D0G                   back to Applesoft, softly
!lm-5

You can nicely EXEC this file from the direct mode, or from a running Applesoft program.  However, in order to use it from a running program, the program must END or STOP.  Do it like this:

!lm+5
100 PRINT CHR$(4)"EXEC LOAD 2ND BANK":END
!lm-5

If you don't END the program, the EXEC file will probably just become part of the input to your Applesoft program, rather than being executed.

HOWEVER....  You can beat the system.  Change the EXEC file to this form:

!lm+5
C089 C089
F800<F800.FFFFM
BLOAD B.BOBANDLEE
C081
D7D2G
!lm-5

And the Applesoft code to this:
!lm+5
100 PRINT CHR$(4)"EXEC LOAD 2ND BANK":CALL-151
!lm-5

Note the two changes in the EXEC file:  the CALL-151 is not there, and 3D0G has become D7D2G.  And in the Applesoft code instead of END we have CALL-151.

The CALL-151 starts up the Apple monitor, which reads the commands from the EXEC file.  The last command jumps to $D7D2, the running entry into Applesoft.  This continues execution of the Applesoft program from the next statement after the CALL-151.
