home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / XMSTEST.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  107 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** XMSTEST.C
  5. **
  6. ** Test extended memory routines in file XMS.C
  7. **
  8. ** Released to the public domain by Cliff Rhodes with no guarantees
  9. ** of any kind.
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #include "xms.h"
  16.  
  17. #define BufSize            30000
  18. #define BlockSize  (long) 130000L
  19.  
  20. int main(void)
  21. {
  22.       int i;
  23.       unsigned int handle1, handle2;       /* XMS handles */
  24.       char *buf1, *buf2;
  25.  
  26.       if ((i = XMSinit()) == 0)
  27.       {
  28.             printf("Extended Memory Manager not found, terminating program\n");
  29.             return 1;
  30.       }
  31.       i = XMSversion();
  32.       printf("Extended Memory Manager Version %d.%d is installed\n",
  33.              i >> 8, (i & 0xff));
  34.  
  35.       printf("There are %ld extended memory bytes available\n", XMScoreleft());
  36.  
  37.       buf1 = malloc(BufSize);
  38.       buf2 = malloc(BufSize);
  39.       if (buf1 == NULL || buf2 == NULL)
  40.       {
  41.             printf("Error allocating conventional memory\n");
  42.             return 1;
  43.       }
  44.       for (i = 0; i < BufSize; i++)   /* Fill buf1 with some values */
  45.       {
  46.             buf1[i] = i % 255;
  47.             buf2[i] = 0;
  48.       }
  49.       handle1 = XMSalloc(BlockSize);
  50.       if (handle1 == 0)
  51.       {
  52.             printf("Error allocating XMS memory for handle 1\n");
  53.             return 1;
  54.       }
  55.       printf("Handle 1 is %u and represents %ld bytes\n", handle1, BlockSize);
  56.       printf("There are %ld extended memory bytes available\n", XMScoreleft());
  57.  
  58.       handle2 = XMSalloc(BlockSize);
  59.       if (handle2 == 0)
  60.       {
  61.             XMSfree(handle1);
  62.             printf("Error allocating XMS memory for handle 2\n");
  63.             return 1;
  64.       }
  65.       printf("Handle 2 is %u and represents %ld bytes\n", handle2, BlockSize);
  66.       printf("There are %ld extended memory bytes available\n", XMScoreleft());
  67.  
  68.       /* Copy data from DOS buf1 to XMS memory of handle1 */
  69.  
  70.       if (DOStoXMSmove(handle1, 0L, buf1, (long) BufSize) != BufSize)
  71.             printf("DOStoXMS copy failed\n");
  72.  
  73.       /* Copy XMS handle1 data to XMS handle2 */
  74.  
  75.       if (XMSmemcpy(handle2, 0L, handle1, 0L, BlockSize) != BlockSize)
  76.             printf("XMS copy failed\n");
  77.  
  78.       /* Copy XMS handle2 data to DOS buf2 */
  79.  
  80.       if (XMStoDOSmove(buf2, handle1, 0L, (long) BufSize) != BufSize)
  81.             printf("XMStoDOS copy failed\n");
  82.  
  83.       /* buf1 data should now == buf2 data */
  84.  
  85.       for (i = 0; i < BufSize; i++)
  86.       {
  87.             if (buf1[i] != buf2[i])
  88.             {
  89.                   printf("*** ERROR: Mismatch in DOS buffers at "
  90.                          "location %d ***\n", i);
  91.                   break;
  92.             }
  93.       }
  94.       free(buf1);
  95.       free(buf2);
  96.  
  97.       XMSfree(handle2);
  98.       printf("There are %ld bytes available after freeing handle 2\n",
  99.              XMScoreleft());
  100.  
  101.       XMSfree(handle1);
  102.       printf("There are %ld bytes available after freeing handle 1\n",
  103.              XMScoreleft());
  104.  
  105.       return 0;
  106. }
  107.