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

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** EMSTEST.C
  5. **
  6. ** Test EMS functions found in ems.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 <dos.h>
  14.  
  15. #include "ems.h"
  16.  
  17. int main(void)
  18. {
  19.       const char str[] = "This is just a test string!";
  20.       int i, ver, handle1, handle2;
  21.       unsigned int baseaddress;
  22.       char far *cp;
  23.  
  24.       /* Get the segment for mapping expanded memory into address space */
  25.  
  26.       if((baseaddress = EMSbaseaddress()) == 0)
  27.       {
  28.             printf("Expanded memory manager not found, "
  29.                    "terminating program.\n");
  30.             return 1;
  31.       }
  32.  
  33.       /* Get the version number an the number of pages available */
  34.  
  35.       ver = EMSversion();
  36.       printf("EMM Version %d.%d loaded\n", ver >> 4, ver & 0x0f);
  37.       printf("There are %d pages available\n", EMSpages());
  38.  
  39.       /* Allocate a few pages */
  40.  
  41.       handle1 = EMSalloc(3);   /* Allocate 3 pages */
  42.       if(handle1 < 0)
  43.       {
  44.             printf("EMM allocation failed on handle 1\n");
  45.             return 1;
  46.       }
  47.       handle2 = EMSalloc(1);   /* Allocate 1 page */
  48.       if(handle2 < 0)
  49.       {
  50.             EMSfree(handle1);
  51.             printf("EMM allocation failed on handle 2\n");
  52.             return 1;
  53.       }
  54.       printf("There are %d pages available after allocating 4\n", EMSpages());
  55.  
  56.       /* Map the allocated pages into the address space */
  57.  
  58.       if(EMSmap(0, handle1, 1) < 0)            /* Mapped page 1 into bank 0 */
  59.             printf("Error mapping handle 1\n");
  60.       if(EMSmap(3, handle2, 0) < 0)            /* Mapped page 0 into bank 3 */
  61.             printf("Error mapping handle 2\n");
  62.       else
  63.       {
  64.             /* Write test string into beginning of handle2 */
  65.  
  66.             cp = (char far *) (MK_FP(baseaddress, 3 * EMS_PAGE_SIZE));
  67.             for(i = 0; str[i]; i++)
  68.                   cp[i] = str[i];
  69.             cp[i] = '\0';
  70.  
  71.             /* Read back test string and look for a match */
  72.  
  73.             cp = (char far *) (MK_FP(baseaddress, 3 * EMS_PAGE_SIZE));
  74.             for(i = 0; str[i]; i++)
  75.             {
  76.                   if(cp[i] != str[i])
  77.                   {
  78.                         printf("Data mismatch at character %d\n", i);
  79.                         break;
  80.                   }
  81.             }
  82.       }
  83.       EMSfree(handle1);
  84.       EMSfree(handle2);
  85.  
  86.       return 0;
  87. }
  88.