home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv4_4 / xms / scrsave.c next >
Encoding:
C/C++ Source or Header  |  1988-11-02  |  3.1 KB  |  122 lines

  1. /****************************************************************************/
  2. /*                                        */
  3. /*  SCRSAVE.C -                         Chip Anderson   */
  4. /*                                        */
  5. /*    XMS Demonstration Program.  Saves the contents of the text screen   */
  6. /*    in extended memory, writes a test pattern on the screen, then        */
  7. /*    restores the screen's original contents.  11/1/88            */
  8. /*                                        */
  9. /****************************************************************************/
  10.  
  11. #include "stdio.h"
  12.  
  13. #define WORD        unsigned int
  14.  
  15. WORD XMM_Installed(void);
  16. WORD XMM_Version(void);
  17. long XMM_AllocateExtended(WORD);
  18. long XMM_FreeExtended(WORD);
  19. long XMM_MoveExtended(struct XMM_Move *);
  20.  
  21. struct XMM_Move
  22.   {
  23.     unsigned long   Length;
  24.     unsigned int    SourceHandle;
  25.     unsigned long   SourceOffset;
  26.     unsigned int    DestHandle;
  27.     unsigned long   DestOffset;
  28.   };
  29.  
  30. #define XMSERROR(x)    (unsigned char)((x)>>24)
  31.  
  32. /*--------------------------------------------------------------------------*/
  33. /*                                        */
  34. /*  main() -                                    */
  35. /*                                        */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. main()
  39.  
  40. {
  41.   int            i,j;
  42.   long            lret;
  43.   WORD            xHandle = 0;
  44.   struct XMM_Move   MoveStruct;
  45.  
  46.   /* Display the credits. */
  47.   printf("SCRSAVE - XMS Demonstration Program\n");
  48.  
  49.   /* Is an XMS Driver installed? */
  50.   if (!XMM_Installed())
  51.     {
  52.       printf("No XMS Driver was found.\n");
  53.       exit(-1);
  54.     }
  55.  
  56.   /* Is it a version 2.00 driver (or higher)? */
  57.   if (XMM_Version() < 0x200)
  58.     {
  59.       printf("This program requires an XMS driver version 2.00 or higher.\n");
  60.       exit(-1);
  61.     }
  62.  
  63.   /* We've found a legal XMS driver.  Now allocate 8K of extended memory for
  64.      the screen. */
  65.  
  66.   lret = XMM_AllocateExtended(8);
  67.   xHandle = (WORD)lret;
  68.  
  69.   if (!xHandle)
  70.     {
  71.       printf("Allocation Error: %X\n", XMSERROR(lret));
  72.       exit(-1);
  73.     }
  74.  
  75.   /* Copy the contents of the screen video buffer into the extended memory
  76.      block we just allocated. */
  77.  
  78.   MoveStruct.SourceHandle = 0;        /* Source is in conventional memory */
  79.   MoveStruct.SourceOffset = 0xB8000000L;/* Text screen data is at B800:0000 */
  80.   MoveStruct.DestHandle   = xHandle;
  81.   MoveStruct.DestOffset   = 0L;
  82.   MoveStruct.Length      = 8000L;    /* 80 x 25 x 4 */
  83.  
  84.   lret = XMM_MoveExtended(&MoveStruct);
  85.  
  86.   if (!(WORD)lret)
  87.     {
  88.       printf("Memory Move Error: %X\n", XMSERROR(lret));
  89.       exit(-1);
  90.     }
  91.  
  92.   /* Fill the screen with garbage. */
  93.   for (i=0; i < 22; i++)
  94.       for (j=64; j < (64+81); j++)
  95.       printf("%c",j);
  96.  
  97.   /* Prompt the user. */
  98.   printf("Press Enter to restore the screen:");
  99.   getchar();
  100.  
  101.   /* Restore the screen buffer. */
  102.   MoveStruct.DestHandle   = 0;
  103.   MoveStruct.DestOffset   = 0xB8000000L;
  104.   MoveStruct.SourceHandle = xHandle;
  105.   MoveStruct.SourceOffset = 0L;
  106.   MoveStruct.Length      = 8000L;
  107.  
  108.   lret = XMM_MoveExtended(&MoveStruct);
  109.  
  110.   if (!(WORD)lret)
  111.     {
  112.       printf("Memory Move Error: %X\n", XMSERROR(lret));
  113.       exit(-1);
  114.     }
  115.  
  116.   /* Free the extended memory buffer. */
  117.   XMM_FreeExtended(xHandle);
  118.  
  119.   printf("Program terminated normally.");
  120.   exit(0);
  121. }
  122.