home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / xms.cpp < prev   
C/C++ Source or Header  |  1995-02-11  |  1KB  |  78 lines

  1. // ------------- xms.cpp
  2. // Extended Memory Specification (XMS) Driver Functions
  3.  
  4. #include "xms.h"
  5.  
  6. static void far (*xmscall)();
  7.  
  8. // ------- test for XMS installed in system
  9. int xms_present()
  10. {
  11.     _AX = 0x4300;
  12.     geninterrupt(0x2f);
  13.     if (_AL != 0x80)
  14.         return 0;
  15.     _AX = 0x4310;
  16.     geninterrupt(0x2f);
  17.     xmscall = (void far(*)()) (MK_FP(_ES, _BX));
  18.     return 1;
  19. }
  20.  
  21. // ------- return size in KB of largest XMS block available
  22. unsigned xms_available()
  23. {
  24.     _AH = 8;
  25.     (*xmscall)();
  26.     return _AX;
  27. }
  28.  
  29. // ------- allocate block in KB of XMS to an application
  30. int xms_allocate(unsigned blksize)
  31. {
  32.     _DX = blksize;
  33.     _AH = 9;
  34.     (*xmscall)();
  35.     return _DX;
  36. }
  37.  
  38. static struct xms_copyparams    {
  39.     long length;
  40.     int src_handle;
  41.     long src_offset;
  42.     int dest_handle;
  43.     long dest_offset;
  44. } xcp;
  45.  
  46. void xms_free(int handle)
  47. {
  48.     _DX = handle;
  49.     _AH = 0x0a;
  50.     (*xmscall)();
  51. }
  52.  
  53. void copy_xmstoconv(int handle, char far *memblk, long offset, long length)
  54. {
  55.     xcp.src_handle = handle;
  56.     xcp.src_offset = offset;
  57.     xcp.dest_handle = 0;
  58.     xcp.dest_offset = (long) memblk;
  59.     xcp.length = length;
  60.     _SI = (unsigned) &xcp;
  61.     _AH = 0x0b;
  62.     (*xmscall)();
  63. }
  64.  
  65. void copy_convtoxms(int handle, char far *memblk, long offset, long length)
  66. {
  67.     xcp.src_handle = 0;
  68.     xcp.src_offset = (long) memblk;
  69.     xcp.dest_handle = handle;
  70.     xcp.dest_offset = offset;
  71.     xcp.length = length;
  72.     _SI = (unsigned) &xcp;
  73.     _AH = 0x0b;
  74.     (*xmscall)();
  75. }
  76.  
  77.  
  78.