home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / XMS11.ZIP / XMSHRW.CPP < prev   
Encoding:
C/C++ Source or Header  |  1990-08-31  |  4.5 KB  |  132 lines

  1. // Turbo C++ XMS Interface Library
  2. // by Richard Vuduc
  3. // Copyright 1990, Richard Vuduc
  4.  
  5. // MODULE: XMSHRW.CPP
  6. // The module contains the source for the individual read/writes.
  7. // You may modify this to accomodate your own data types
  8. // See the manual for additional details on making your own
  9. // Get/Store functions.
  10.  
  11. #include "xms.h"
  12. extern XMSDriver *xmsptr;
  13.  
  14. // *********Basic Steps
  15. // In general, your get/store routines should do the following
  16. //
  17. //    1) Confirm the state of the cache.  You can do this with
  18. //       a simple GetCache call.  It returns True if the cache
  19. //       is in.
  20. //    2) If the cache is installed, call cache update.  Cache
  21. //       Update will update the cache if the current Index
  22. //       is not within the cache.  If you are doing a Store
  23. //       function, be sure that you do an additional 'CBounds'
  24. //       call to determine whether or not the ENTIRE data
  25. //       item can be found within the cache.  If not, a full
  26. //       cache update needs to be performed.
  27. //    3) After the CacheUpdate, you can be guaranteed that
  28. //       the data item is in the cache (unless the cache is
  29. //       not large enough to hold all of it).  Using a type
  30. //       cast (see the functions below), you can change
  31. //       the value as necessary.
  32. //    4) If you've determined that there is no data cache,
  33. //       you must perform a DIRECT read/write to extended
  34. //       memory.  If you can guarantee that the cache will
  35. //       allows be ON and AVAILABLE, you can omit this
  36. //       special case handling code.
  37. //    5) Lastly, call IncPtr( sizeof( DataItemType ) );
  38. //       where 'DataItemType' is the type of the data.
  39.  
  40. // *****************Custom single data item Gets************************
  41.  
  42. // Get a 'long' var from extended memory at the current Index pointer
  43. void XMSHandle::Get( long& a )
  44. {
  45.     // If the cache is installed...
  46.     if( GetCache( ) )
  47.     {
  48.         CacheUpdate( sizeof( long ) );         // Update the cache
  49.         a = *( ((long *)Data) + CIndex );      // Get data from the cache
  50.     }
  51.     else                                       // No cache...Get directly
  52.         xmsptr->EMBMoveToCon( &a, Handle, GetPtr( ), sizeof( long ) );
  53.     IncPtr( sizeof( long ) );                  // Increment pointer
  54. }
  55.  
  56. // Get the next integer item
  57. // see also: Get( long )
  58. void XMSHandle::Get( int& a )
  59. {
  60.     if( GetCache( ) )                      // Is the cache in?
  61.     {
  62.         CacheUpdate( sizeof( int ) );      // Yes, update the cache
  63.         a = *( (int *)(Data)+CIndex );     // Get from data cache
  64.     }
  65.     else                                   // Nope, direct read
  66.         xmsptr->EMBMoveToCon( &a, Handle, GetPtr( ), sizeof( int ) );
  67.     IncPtr( sizeof( int ) );               // Increment the pointers
  68. }
  69.  
  70. // Get the next character item
  71. void XMSHandle::Get( char& a )
  72. {
  73.     char t[2];           // Tvar used if the cache is off...(direct reads)
  74.     if( GetCache( ) )    // Is the cache on?
  75.     {
  76.         CacheUpdate( );         // Update the cache
  77.         a = *((char *)(Data)+CIndex);   // Get from the cache buffer
  78.     }
  79.     else                        // No cache in, do a direct read
  80.     {
  81.         // Because the XMSDriver and HIMEM expect an even length,
  82.         // two bytes must be retrieved.
  83.         xmsptr->EMBMoveToCon( t, Handle, GetPtr( ), 2 );
  84.         a = *t;
  85.     }
  86.     IncPtr( sizeof( char ) );   // Increment the pointer
  87. }
  88.  
  89. // ******************** Custom Store Functions **************************
  90.  
  91. // Store a long var into extended memory
  92. void XMSHandle::Store( long& a )
  93. {
  94.     if( GetCache( ) )            // The cache must be installed
  95.     {
  96.         CacheUpdate( sizeof( long ) );          // Update the cache
  97.         *((long *)(Data)+CIndex) = (long) a;    // Retrieve from cache
  98.     }
  99.     else                // No cache installed, do a direct write
  100.         xmsptr->EMBMoveToExt( Handle, GetPtr( ), &a, sizeof( long ) );
  101.     IncPtr( sizeof( long ) );
  102. }
  103.  
  104. void XMSHandle::Store( int& a )
  105. {
  106.     if( GetCache( ) )               // Cache in?
  107.     {
  108.         // The cache is in so update the cache
  109.         CacheUpdate( sizeof( int ) );
  110.         *((int *)(Data) + CIndex) = (int) a;
  111.     }
  112.     else                            // Write to extended memory
  113.         xmsptr->EMBMoveToExt( Handle, GetPtr( ), &a, sizeof( int ) );
  114.     IncPtr( sizeof( int ) );        // Increment the pointer
  115. }
  116.  
  117. // Store a character variable
  118. void XMSHandle::Store( char& a )
  119. {
  120.     char t[2];    // Remember that direct rd/write lengths must be even
  121.     *t = a;
  122.     if( GetCache( ) )
  123.     {
  124.         CacheUpdate( );
  125.         *((char *)(Data) + CIndex) = (char) a;
  126.     }
  127.     else
  128.         xmsptr->EMBMoveToExt( Handle, GetPtr( ), &t, 2 );
  129.     IncPtr( sizeof( char ) );
  130. }
  131. // END XMSHRW.CPP
  132.