home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / XMSLIB12.ZIP / XMS.C next >
Encoding:
C/C++ Source or Header  |  1991-03-08  |  4.5 KB  |  113 lines

  1. /*
  2.     This program will determine whether or not an XMS driver is
  3.     installed, and will return several statistics about it if
  4.     a driver is found.
  5.  
  6.     It will also test most of the XMSLIB routines.
  7.  
  8.     USE AT YOUR OWN RISK
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #include "xmslib.h"
  15.  
  16.  
  17. int main()
  18. {
  19.     unsigned char error;    /* error code returned be most routines */
  20.     unsigned int freemem, totmem;   /* memory stats */
  21.     unsigned int ver_proto, ver_driver, hma_avail;  /* version stats */
  22.     unsigned int state; /* state of the A20 line. */
  23.     unsigned int handle;    /* EMB handle allocated */
  24.     void far *address;  /* pointer to EMB.  Note:  this is a 32bit linear    */
  25.                         /* address, so it cannot be used directly.           */
  26.     unsigned char locks, fhandles;  /* locks on the handle, and handles free */
  27.     unsigned int blength;   /* size of the block (for info request) */
  28.     unsigned int maxumb, segaddr;   /* for UMB request.  (not on MY machine!) */
  29.     char    message[30]  = "This be a test.";   /* for extended mem move    */
  30.     char    message2[30] = "xxxxxxxxxxxxxxx";   /*  "     "      "   "      */
  31.  
  32.     struct EMMMoveStruct moverec; /* also for extended memory move          */
  33.  
  34.     if(!XMS_Setup()) {  /* must be called before using any other XMS function */
  35.         printf("There seems to be no XMS driver installed!\n");
  36.         exit(1);
  37.     }
  38.     XMS_Version(&ver_proto, &ver_driver, &hma_avail);
  39.     printf("XMS Status:  Protocol version: %x  Internal version: %x  HMA avail: %s\n",
  40.                 ver_proto, ver_driver, hma_avail ? "Yes" : "No");
  41.     if(ver_proto!=0x0200) {
  42.         printf("Protocol version is NOT 2.00, so I'm gonna FREAK!\n");
  43.         exit(1);
  44.     }
  45.     XMS_FreeMem(&freemem,&totmem);  /* query free XMS memory */
  46.     printf("XMS Status:  %dk total, %dk total\n", totmem, freemem);
  47.     printf("Allocate HMA: %x\n",XMS_RequestHMA(0xffff));
  48.     printf("Release HMA: %x\n",XMS_ReleaseHMA());
  49.     printf("GlobalDisableA20: %x :",XMS_GlobalDisableA20());
  50.  
  51.     XMS_QueryA20(&state);
  52.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  53.     printf("LocalEnableA20: %x :",XMS_LocalEnableA20());
  54.  
  55.     XMS_QueryA20(&state);
  56.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  57.     printf("LocalDisableA20: %x :",XMS_LocalDisableA20());
  58.  
  59.     XMS_QueryA20(&state);
  60.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  61.  
  62.     error = XMS_AllocEMB(10,&handle); /* allocate 10k of memory */
  63.     printf("AllocEMB: %x   handle: %x\n",error, handle);
  64.  
  65. /* next, copy our little message to extended memory */
  66.     moverec.Length = sizeof(message);
  67.     moverec.SourceHandle = 0;   /* handle of 0 means direct memory */
  68.     moverec.SourceOffset = (unsigned long)message;
  69.     moverec.DestHandle = handle;    /* our EMB handle */
  70.     moverec.DestOffset=0;   /* copy to the front of the block */
  71.     error = XMS_MoveEMB(&moverec);
  72.     printf("MoveEMB: %x\n",error);
  73.     printf("String 1: %s\nString 2: %s\n",message, message2);
  74.  
  75.     moverec.Length = sizeof(message);   /* now, move it to the second string */
  76.     moverec.DestHandle = 0;
  77.     moverec.DestOffset = (unsigned long)message2;
  78.     moverec.SourceHandle = handle;
  79.     moverec.SourceOffset=0;
  80.     error = XMS_MoveEMB(&moverec);
  81.     printf("MoveEMB: %x\n",error);
  82.     printf("String 1: %s\nString 2: %s\n",message, message2);
  83.  
  84.     error = XMS_LockEMB(handle, &address);
  85.     printf("Handle %x located at linear memory address %p\n",handle, address);
  86.     printf("Lock returned error %x\n",error);
  87.  
  88.     error = XMS_ReallocEMB(handle, 20); /* reallocate as 20k instead of 10 */
  89.     printf("ReallocEMB: %x\n",error);   /* THIS SHOULD FAIL BECAUSE OF LOCK */
  90.  
  91.     error = XMS_GetEMBHandleInfo(handle, &locks, &fhandles, &blength);
  92.     printf("Info on handle %x: Locks: %d Free handles: %d Block length: %d\n",
  93.         handle, locks, fhandles, blength);
  94.  
  95.     error = XMS_UnlockEMB(handle);
  96.     printf("Unlock returned error %x\n",error);
  97.  
  98.     error = XMS_ReallocEMB(handle, 20); /* reallocate as 20k instead of 10 */
  99.     printf("ReallocEMB: %x\n",error);
  100.  
  101.     error = XMS_GetEMBHandleInfo(handle, &locks, &fhandles, &blength);
  102.     printf("Info on handle %x: Locks: %d Free handles: %d Block length: %d\n",
  103.         handle, locks, fhandles, blength);
  104.  
  105.     error = XMS_FreeEMB(handle); /* free memory */
  106.     printf("FreeEMB: %x\n",error);
  107.  
  108.     error = XMS_RequestUMB(0xffff, &segaddr, &maxumb);
  109.     printf("RequestUMB: %x  MaxSize: %d\n",error, maxumb);
  110.  
  111.     return 0;
  112. }
  113.