home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XSWAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-30  |  3.5 KB  |  106 lines

  1. /*************************************************************************/
  2. /* The original for this module (before I hacked it all up) came from    */
  3. /* Turbopower Software with a license to use freely as long as credit    */
  4. /* was given.  The original module (not hacked up) is available from     */
  5. /* Mike Ratledge.  You'll probably want to FReq it from him              */
  6. /* (MIKESWAP.ZIP last I heard) for additional info.                      */
  7. /*                                                                       */
  8. /* Oh, yeah, this swaps the TC 2.0 program running to disk/EMS           */
  9. /*************************************************************************/
  10.  
  11. #include "msg.h"
  12. #include "xext.h"
  13.  
  14. extern char pascal ALLOCATESWAPFILE(void);
  15. extern char pascal EMSINSTALLED(void);
  16. extern unsigned int pascal EMSPAGEFRAME(void);
  17. extern char pascal ALLOCATEEMSPAGES (unsigned);
  18. extern pascal EXECWITHSWAP (char far *, char far *);
  19. extern void pascal DEALLOCATEEMSHANDLE(unsigned);
  20. extern huge FIRSTTOSAVE(void);
  21. extern pascal DEALLOCATESWAPFILE(void);
  22.  
  23. char   SwapName[28];
  24. unsigned long BytesSwapped;
  25. unsigned int  PrefixSeg;
  26. char           FileAllocated=0;
  27. unsigned int  EmsHandle;
  28. char           EmsAllocated;
  29. unsigned int  FrameSeg;
  30. unsigned int  FileHandle;
  31. unsigned       EmsPageSize=16384;
  32.  
  33. #define FALSE 0
  34.  
  35. extern unsigned _psp;
  36.  
  37.  
  38. int pascal doswap (char far *command_str, char far *args) {
  39.  
  40.  char exec_tail[128], exec_file[128], far *ivt, huge *end_mem,
  41.      huge *start_mem, far *vptr;
  42.  struct time dos_time;
  43.  int swapcode;
  44.  long freefarmem;
  45.  unsigned EMS_pagesneeded;
  46.  extern char **_heaptop;
  47.  
  48.   if(!strchr(command_str,'.')) {
  49.         say_prompt(441);
  50.         gprintf(LOCALONLY | LOGONLY,"Prg name: `%s'\n",command_str);
  51.         return 255;
  52.   }
  53.   gettime(&dos_time);
  54.   sprintf(SwapName,"%c:%02u%02u%02uXB.S%02x",conf.useswapdisk,dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec,nodenumber);
  55.   vptr = MK_FP(0x0000, 0x0000);
  56.   ivt = farmalloc(1024);
  57.   start_mem = (char huge *) FIRSTTOSAVE;
  58.   end_mem = (char huge *) _heaptop;
  59.   freefarmem = farcoreleft();
  60.   if (freefarmem < 3072) freefarmem = 0;
  61.   else freefarmem -= 3072;
  62.   BytesSwapped = (unsigned long) (end_mem - start_mem) - freefarmem;
  63.  
  64.   PrefixSeg = _psp;
  65.  
  66.   cprintf("\r\n");
  67.   clreol();
  68.   if ((conf.LIMEMS) && (EMSINSTALLED ())) {
  69.     EMS_pagesneeded = (unsigned) ((BytesSwapped + EmsPageSize + 1) / EmsPageSize);
  70.     if ((EmsHandle = ALLOCATEEMSPAGES (EMS_pagesneeded)) != 0xffff) {
  71.       EmsAllocated = 1;
  72.       FrameSeg = EMSPAGEFRAME();
  73.       cprintf("Swapping %lu bytes to EMS - %u pages (%dk)\r\n", BytesSwapped, EMS_pagesneeded, 16 * EMS_pagesneeded);
  74.     }
  75.   }
  76.   else EmsAllocated = FALSE;
  77.   if (!EmsAllocated && (FileAllocated = ALLOCATESWAPFILE ()) == 0) {
  78.     clreol();
  79.     cprintf("ERROR! Cannot Swap\r\n");
  80.     return(-1);
  81.   }
  82.   if (FileAllocated) cprintf("Swapping %lu bytes to `%s'...\r\n", BytesSwapped, SwapName);
  83.   strcpy (exec_file, command_str);
  84.   strcpy (exec_tail, " ");
  85.   strcat (exec_tail, args);
  86.   strcat (exec_tail, "\r");
  87.   exec_tail[0] = (char) strlen (exec_tail) - 2;
  88.   disable();
  89.   memcpy((char far *) ivt, (char far *) vptr, 1024);
  90.   enable();
  91.   swapcode = EXECWITHSWAP ((char far *) exec_file, (char far *) exec_tail);
  92.   disable();
  93.   memcpy((char far *) vptr, (char far *) ivt, 1024);
  94.   enable();
  95.   if (EmsAllocated) {
  96.     DEALLOCATEEMSHANDLE (EmsHandle);
  97.     EmsAllocated = 0;
  98.   }
  99.   else if (FileAllocated) {
  100.     DEALLOCATESWAPFILE ();
  101.     FileAllocated = 0;
  102.   }
  103.   farfree ((char far *) ivt);
  104.   return (swapcode);
  105. }
  106.