home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / SWAPBAS.ZIP / SWAPOUT.BAS < prev   
BASIC Source File  |  1994-02-16  |  3KB  |  90 lines

  1.  
  2. ' This function returns the ErrorLevel in ELRC%
  3. ' Program memory is swapped to EMS/XMS/DISK, whichever is found first
  4. ' Link SWAPBAS.OBJ into your program FIRST so as to reduce the 
  5. ' memory requirements can leave a stub file as small as 2400 bytes
  6.  
  7. ' Prog2Run$ MUST be a fully named file, the path is NOT searched!!!!
  8.  
  9. ' It is a GOOD idea to fully name SwapFile$ also because a disaster could
  10. ' occur if it is not found on return
  11.  
  12. ' Memory.Swap returns TRUE (-1) if a successful swap occured
  13. ' or FALSE (0) if the swap failed
  14.  
  15. DECLARE FUNCTION Memory.Swap% (Prog2Run$, ProgCmdLine$, ELRC%, SwapFile$)
  16. DECLARE FUNCTION XMScheck% ()
  17. DECLARE FUNCTION EMScheck% ()
  18. DECLARE FUNCTION SWAPBAS% (SEG SwapPack AS ANY)
  19.  
  20. TYPE SwapPackTYPE         'Do not change the sizes of these*
  21.  statexec AS INTEGER      'To simplify this use this static structure
  22.  ProgName AS STRING * 128 'to pass info. The 384 bytes it uses is made
  23.  CmdLine AS STRING * 126  'up in ease-of-use and the lack of need to
  24.  SaveFile AS STRING * 128 'constantly assign pointers if these were such.
  25. END TYPE                  '(*unless you change the SWAPBAS.ASM source)
  26. DIM SWAPIT AS SwapPackTYPE
  27.  
  28. ' EXAMPLE CODE
  29. 'Prog2Run$ = COMMAND$
  30. 'Swapfile$ = "swapper.swp"
  31. 'a% = Memory.Swap%(prog2run$,progcmdline$,ELRC%,swapfile$)
  32. 'PRINT "Error level returned is"; ELRC%
  33. 'CLOSE ' I do this before I end ANY program
  34. 'CLEAR ' I do this before I end ANY program
  35. 'end
  36.  
  37. FUNCTION Memory.Swap% (prog2run$, progcmdline$, ELRC%, SwapFile$)
  38. SHARED SWAPIT AS SwapPackTYPE
  39. SHARED Memoryswapping
  40. IF progcmdline$ = "" THEN progcmdline$ = " "
  41. IF SwapFile$ = "" THEN SwapFile$ = "A1B2C3E4.SWP"
  42. LastLine = CSRLIN
  43. PCOPY 0, 1
  44. CLS
  45. SWAPIT.statexec = 0
  46. SWAPIT.ProgName = prog2run$ + CHR$(0)
  47. SWAPIT.CmdLine = progcmdline$ + CHR$(0)
  48. SWAPIT.SaveFile = SwapFile$ + CHR$(0)
  49. SELECT CASE Memoryswapping
  50. CASE 0
  51. PRINT "Swapping ..."
  52. statSWAP = SWAPBAS(SWAPIT)
  53. IF statSWAP THEN
  54.    Memory.Swap% = 0
  55.    SELECT CASE statSWAP
  56.    CASE 1
  57.    PRINT "Memory SWAP failed; Unable to shrink DOS memory block"
  58.    CASE 2
  59.    PRINT "Memory SWAP failed; Unable to save current task to EMS/XMS/DISK"
  60.    CASE 3
  61.    PRINT "Memory SWAP failed; Unable to execute " + prog2run$
  62.         SELECT CASE SWAPIT.statexec
  63.            CASE 2
  64.            PRINT "File not found"
  65.            CASE 5
  66.            PRINT "Access denied"
  67.            CASE 8
  68.            PRINT "Insufficient memory"
  69.            CASE ELSE
  70.            END SELECT
  71.         CASE ELSE
  72.         END SELECT
  73.             PRINT "Executing " + prog2run$ + " in a standard DOS shell"
  74.             SHELL prog2run$ + " " + progcmdline$
  75. ELSE
  76. PRINT prog2run$ + " returns errorlevel" + STR$(SWAPIT.statexec)
  77. ELRC% = SWAPIT.statexec
  78. Memory.Swap% = statSWAP
  79. END IF
  80. CASE 1
  81.         SHELL prog2run$ + " " + progcmdline$
  82.         Memory.Swap% = -1
  83. CASE ELSE
  84. END SELECT
  85. SLEEP 3
  86. PCOPY 1, 0
  87. LOCATE LastLine
  88. END FUNCTION
  89.  
  90.