home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / tt / vmem11 / vmem_prg / vm_copy.c < prev    next >
C/C++ Source or Header  |  1990-07-30  |  2KB  |  81 lines

  1. #include "vmem.h"
  2.  
  3. /**********************************************/
  4. /* Kopieren eines Bereiches in einen anderen: */
  5. /**********************************************/
  6.  
  7. long vm_copy (source, destination, long)
  8.     V_ADR source, destination;
  9.     long count;
  10. {
  11.     BYTE    *page_ptr;
  12.     VPAGE    page_s, page_d;
  13.     WORD    offset_s, offset_d;
  14.     long    entry_size, size_s, size_d;
  15.  
  16.     page_s = GET_PAGE (source);
  17.     offset_s = GET_OFFSET (source);
  18.     page_d = GET_PAGE (destination);
  19.     offset_d = GET_OFFSET (destination);
  20.  
  21. #ifdef DEBUG
  22.     printf ("VM_LOAD: page_s: %x  offset_s: %x\n", page_s, offset_s);
  23.     printf ("         page_d: %x  offset_d: %x\n", page_d, offset_d);
  24. #endif
  25.  
  26.     if ((page_s >= info.count_page) || (flags [page_s] == FREE)
  27.     ||  (page_d >= info.count_page) || (flags [page_d] == FREE))
  28.         return (ILLEGAL_ADDRESS);
  29.  
  30.     if ((count == 0) || (count < -1))
  31.         return (ILLEGAL_COUNT);
  32.  
  33.     size_s = PAGE_TO_ADDR (MD_COUNT (md_find (page_s)));
  34.     size_d = PAGE_TO_ADDR (MD_COUNT (md_find (page_d)));
  35.  
  36.     if (count == -1)
  37.         count = MIN ((size_s - offset_s), (size_d - offset_d));
  38.     else
  39.         count = MIN (count, MIN ((size_s - offset_s), (size_d - offset_d)));
  40.  
  41.     entry_size = count;
  42.  
  43.     if (offset_s > 0)
  44.     {
  45.         long    size = info.page_size - offset_s;
  46.         
  47.         page_ptr = load_page (vmem_page++, CACHE_READ) + start_offset;
  48.         if (count <= size)
  49.         {
  50.             memcpy (destination, page_ptr, count);
  51.             return (count);
  52.         }
  53.         else
  54.         {
  55.             memcpy (destination, page_ptr, size);
  56.             destination += size;
  57.             entry_size -= size;
  58.         }
  59.     }
  60.  
  61.     if (entry_size >= info.page_size)
  62.     {
  63.         do
  64.         {
  65.             page_ptr = load_page (vmem_page++, CACHE_READ);
  66.             memcpy (destination, page_ptr, info.page_size);
  67.             destination += info.page_size;
  68.             entry_size -= info.page_size;
  69.         }
  70.         while (entry_size >= info.page_size);
  71.     }
  72.  
  73.     if (entry_size > 0)
  74.     {
  75.         page_ptr = load_page (vmem_page, CACHE_READ);
  76.         memcpy (destination, page_ptr, entry_size);
  77.     }
  78.  
  79.     return (count);
  80. }
  81.