home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / graph / egasave / svscreen.c < prev   
Encoding:
C/C++ Source or Header  |  1988-01-10  |  2.5 KB  |  91 lines

  1. #include <graph.h>
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <dos.h>
  5. #include <malloc.h>
  6.  
  7.  
  8. /*        Program for saving the EGA screen FAST       */
  9. /*        This version for MSC 5.0 C, small model      */
  10. /*        Uses 28K buffer in data segment, you may     */
  11. /*        need change the program to use a smaller     */ 
  12. /*        buffer if data space is at a premium.  This  */
  13. /*        version works well for a fast "slide show"   */
  14. /*        type of effect where there is not much       */
  15. /*        program data.                                */
  16. /*                                                     */
  17. /*        If using a model with a large data segment   */
  18. /*        so that all data calls are far, then the     */
  19. /*        buffer is not needed, you can fwrite         */
  20. /*        directly from video memory.                  */
  21. /*                                                     */
  22. /*        usage:    error = save_screen(filename);     */
  23. /*                  error is type int                  */
  24. /*                  filename is char array of size 13  */
  25. /*                  error returned as stated below     */
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. unsigned char buffer[28000];   /* buffer for one plane of video mem */
  37.  
  38.  
  39.  
  40.  
  41. save_screen (filename)
  42.  
  43. char *filename;   /*  file name passed from calling program */
  44.  
  45. {
  46.  
  47.       unsigned char plane;    /* variable to hold current video plane */
  48.       int flag;          /* Error Flag */
  49.                          /* 0 = success */
  50.                          /* 1 = open file error */
  51.                          /* 2 = write file error */
  52.  
  53.       FILE *screen_save;
  54.       struct SREGS segregs;    /* structure for segread call */
  55.  
  56.  
  57.       segread(&segregs);
  58.  
  59.       if ((screen_save = fopen(filename, "wb")) == NULL)
  60.             return(1);
  61.  
  62.  
  63.       for (plane = 0; plane < 4; plane++)
  64.          {
  65.              outp(0x3CE, 4);
  66.              outp(0x3CF, plane);
  67.  
  68.              movedata(0xA000, 0x0000, segregs.ds, (unsigned int)buffer, 28000);
  69.  
  70.                /* 0xA000 = segment for EGA video memory */
  71.                /* 0x0000 = offset  for EGA video memory */
  72.                /* segregs.ds = segment for variable "buffer" */
  73.                /* (unsigned int)buffer = offset for variable "buffer" */
  74.                /* 28000 is the byte size of one video plane */
  75.  
  76.              fwrite(buffer,1,28000,screen_save);
  77.              if (ferror(screen_save))
  78.                   return(2);
  79.  
  80.           }
  81.  
  82.  
  83.     fclose(screen_save);
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91.