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 / gtscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-10  |  3.6 KB  |  132 lines

  1. #include <graph.h>
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <dos.h>
  5. #include <malloc.h>
  6.  
  7. /*       error =  get_screen(filename);               */
  8. /*                                                    */
  9. /*       Routine for retrieving EGA screens           */
  10. /*       Used for 16 color 350x640 resolution         */
  11. /*       No packing or unpacking of image             */
  12. /*       Created for MSC V5.0  small model            */
  13. /*                                                    */
  14. /*       error of type int, returned as below         */
  15. /*       filename - array of type char, length 13     */
  16. /*       Routine uses a 28K buffer for fast retrieval */
  17. /*       if data segment space is at a premium,       */
  18. /*       could rewrite to use smaller buffers.        */
  19. /*                                                    */
  20. /*       If using a model with a large data space     */
  21. /*       then all data calls are far and no buffer is */
  22. /*       needed.  Use fread to write directly to      */
  23. /*       video memory.                                */
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. /* DEFINE A BUFFER TO HOLD ONE OF THE FOUR PLANES */
  41.  
  42. unsigned char buffer[28000];
  43.  
  44.  
  45.  
  46.  
  47.  
  48. get_screen (filename)
  49.  
  50. char *filename;       /* filename passed, 12 character max */
  51.  
  52. {
  53.         int flag = 0; /* return integer flag     */
  54.                       /* flag = 0  success       */
  55.                       /* flag = 1  error opening */
  56.                       /* flag = 2  error reading */
  57.  
  58.  
  59.         struct SREGS segregs;    /* structure for segread call */
  60.  
  61.         FILE *screen_file;       /* image file */
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         segread(&segregs);       /* get data segment for movedata below */
  68.  
  69.         _setvideomode(_ERESCOLOR);  /* set EGA 640x350 16 color mode */
  70.                                     /* 128 K required */
  71.  
  72.         if (!(_setvideomode(_ERESCOLOR)))
  73.             {
  74.               flag = 3;
  75.               return(flag);
  76.             }
  77.  
  78.         if ((screen_file = fopen(filename,"rb")) != NULL)
  79.  
  80.               {
  81.  
  82.                  outp(0x3C4,2);        /* set color plane for read */
  83.                  outp(0x3C5,0x01);
  84.                  fread(buffer,1,28000,screen_file); /* read 1 plane */
  85.                  movedata(segregs.ds,(unsigned int)buffer,0xA000,0x0000,28000);
  86.  
  87.                  /* segregs.ds is data segment for variable "buffer"  */
  88.                  /* buffer is the offset in that segment for "buffer" */
  89.                  /* A0000000 is the far pointer to EGA video memory   */
  90.                  /*          0xA000 = seg      0x0000 = offset        */
  91.                  /* 28000 is the size of one 640x350 color plane      */
  92.  
  93.  
  94.                                      /* repeat for the other three planes */
  95.                  outp(0x3C4,2);
  96.                  outp(0x3C5,0x02);
  97.                  fread(buffer,1,28000,screen_file);
  98.                  movedata(segregs.ds,(unsigned int)buffer,0xA000,0x0000,28000);
  99.  
  100.  
  101.  
  102.                  outp(0x3C4,2);
  103.                  outp(0x3C5,0x04);
  104.                  fread(buffer,1,28000,screen_file);
  105.                  movedata(segregs.ds,(unsigned int)buffer,0xA000,0x0000,28000);
  106.  
  107.  
  108.  
  109.  
  110.  
  111.                  outp(0x3C4,2);
  112.                  outp(0x3C5,0x08);
  113.                  fread(buffer,1,28000,screen_file);
  114.                  movedata(segregs.ds,(unsigned int)buffer,0xA000,0x0000,28000);
  115.  
  116.            if (ferror(screen_file))      /* check for read error */
  117.                  flag = 2;
  118.  
  119.  
  120.  
  121.         fclose(screen_file);
  122.  
  123.                }
  124.  
  125.  
  126.         else
  127.              flag = 1;    /* set flag if failed to open file */
  128.  
  129.        return(flag);
  130.  
  131.        }
  132.