
     FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH
 FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH
       FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH   FLASH

                     QuickBASIC Program Swapping
                            10 August, 91

                            Good News v1.1
                            --------------
For about a couple years now I have been utilizing a program called
"swap.com" (by Nico Mac) to shell to from a QB program.  This little
jewell will do in a SHELL what we need to be doing from within a QB
program..  I have had 0 (ZER0) problems using swap.com on both a
cheapo DTK 286 clone and a 386 /33.

After this recent attempt to get swap300 converted (well, Joey Lizzi
has done all the real work) and working like a charm with QB programs
I have been very disappointed to have been so close but yet no home
run!
I am ASM illiterate but still have a litle bit of "AirDale" common
sense left.  So I though "if I can figure out what QB does before a
SHELL (as it must do something with memory that allows "swap.com"
to work flawlessly) maybe swap300 will work with some modifications.
Well, I took a little gander at the bcom45 routines (listed with
LIB.EXE) and found the references to "SHELL".  Glory be!!  There were
only a half dozen or so mixed in the 'osstmt' module (I suppose that
is what they're called).  Two of these (besides "B$SHELL" caught my
eye: B$ShellRecover and B$ShellSetup

My heart started beating erratically!  I did the following to the
simple program which had an ON KEY () GOSUB in it.

        I added two DECLARE STATEMENTS:

        DECLARE SUB Setshell alias "b$ShellSetup" ()
        DECLARE SUB Fixshell alias "b$ShellRecover" ()

Then I recompiled it, linked 'swapd.obj' (as I call Joey's
SWAP300 mod) as such:

        BC swapme /w /o;
        Link swapd /noe /FAR /PACKC swapme,swapme.exe,nul,/e;

I then ran the program (with eyes closed).  My God!!  It worked...
So I quickly checked for a 'swapme.com' file (earlier NON ON KEY
Version that worked with swapd) and found it not!!  I was thriled.
I added a BUNCH of dynamic and static string and integer arrays.
Recompiled it and it still ran flawlessly.  OK, sfsg (so far so good).
I then compiled a 128K (in memory) door program.  Found it was
swapping OK except that instead of 2.1k left in memory I was looking
at 42K of FNMAIL(the door) in memory.  I remembered in the SWAP.DOC
file it stated to LINK swap as the FIRST module in a program.  I
KEPT getting crashes and internal errors when the program was run.  So
after about an hour of hair pulling I started some sane elimination
of potential causes.  Well, I first tried getting rid of the /E
(exepack) from link - No go.  Then I took out the /FAR and /PACKC link
options - Woweee!! Perfect-o.  (These options make for smaller programs)
Well, I inserted /FAR and still it worked.  It is obvious that my door
program does not like to swap out with the /PACKC (pack code) LINK
option.  It runs perfectly without /PACKC. I have swapped it several
layers deep and it all comes back. This looks good folks.  I then
tried it with my 230K (in memory) BBS Program (FeatherNet) and it
works great! even with /PACKC.

So my findings:

(1) Joey has done a helluva job with his swap300 conversion - it works
    perfectly!
(2) Some LINK options (/PACKC) make quite a diference from one
    program to another. (You might have to play with them a bit)
(3) We QB programmers appear to have a great tool to use from here on
(4) Don't kill me if this all blows up in my face!

 Here is a small program to illustrate the way to QBswap now:

                                Note
                                ----
 ALWAYS define the strings you use in QBSwap and do not place
 any Quoted strings on the QBSwap command line.  It took me a while
 to see this was keeping my program from swapping.
'-----------------------------
DEFINT A-Z
'$INCLUDE: 'qbswap.bi'
DECLARE SUB Setshell alias "b$ShellSetup" ()
DECLARE SUB Fixshell alias "b$ShellRecover" ()
common shared a$, b$, c$, execret%
a$ = "C:\QEMM\MFT.EXE"
b$ = ""
c$ = "C:\TEST\SWAP.FIL" + CHR$(0)
execval% = 0
 CALL SetShell
 Execret% = qbswap(a$, b$, execval%, c$)
 CALL FixShell
'----------------------------------------

 Remember - LINK 'swap.obj' (whatever you name it) as the first .obj
 on your command line or in a sequence file.
 Always assign every variable passed by QBSwap.  Do not pass quoted strings
 as in Execret% = QBSWAP ("C:\COMMAND.COM", "", 0, "C:\SWAP.FIL"+ CHR$(0)).
 Assign them similarly as in the above program listing.

 Be sure your filename to swap to disk ( "c$" OR "C:\TEST\SWAP.FIL" above)
 is NUL TERMINATED by adding the "+ CHR$(0)" to the filename as I have done
 above.  ( Thanks for reminding me of this Joey).  Without this you can
 anticipate any disk swapping to be erratic and most likely unsuccessful.

 Thanks Joey.  This would not have happened without your espertize.

                Ron Pierce
                FeatherNet Support

