home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wrestore.c < prev    next >
C/C++ Source or Header  |  1991-04-02  |  6KB  |  295 lines

  1. /*! wrestore
  2.  *
  3.  *  wrestore from user save area to screen
  4.  *
  5.  *    note this routine assumes the screen save area
  6.  *    was set up using wsave
  7.  *    and the pointer to it in winsave is NORMALIZED
  8.  */
  9.  
  10. #include  "wscreen.h"
  11. #include  "wsys.h"
  12.  
  13.  
  14.  
  15.  
  16. void wrestore (void)
  17.  
  18.     {
  19.     int     extra, extra2;           /* size of frame surrounding window*/
  20.     unsigned char save_attr;    /* save attribute of window */
  21.  
  22.     unsigned char     far *line_ptr;
  23.  
  24.     WHEAP    *hptr;
  25.     unsigned char   far *area;
  26.  
  27.  
  28.     int    l, t, r, b;    /* co-ords of screen image including frame */
  29.     int     col;
  30.  
  31.     int     movenum;
  32.  
  33.     struct _CHATTR         /* 2 byte char/attr */
  34.         {
  35.         unsigned char c;
  36.         unsigned char a;
  37.         };
  38.     typedef struct _CHATTR far *CHATTR;    /* far pointer to a pair */
  39.  
  40.  
  41. #ifndef TEXTONLY
  42.  
  43.     unsigned int    hn;        /* hercules bank offsets */
  44.     int        color;        /* EGA color bit mask */
  45.     int        t_save;        /* save top line # for each color */
  46.  
  47.     /* graphics mode screen pointers */
  48.     unsigned char far *colptr, far *base, far *base_save;
  49.     unsigned char     latch;
  50.  
  51.     int     t_pix, b_pix;   /* top and bottom pixel rows. */
  52.  
  53.  
  54. #endif
  55.  
  56.  
  57.     #ifndef __TURBOC__
  58.         /* Microsoft C requires an 'intermediary' ptr 
  59.          * to generate correct code.
  60.          */
  61.         void far *msc_ptr;
  62.         
  63.     #endif    /* microsoft fix */
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.     /* check address of save area - if NULL, nothing saved.
  71.      */
  72.     hptr = w0-> winsave;
  73.  
  74.  
  75.  
  76.  
  77.     /* extra lines needed to include the border ?
  78.      *       remember that winleft, top etc refer to the text parts,
  79.      *    and if a border is present, need to restore 1 extra line
  80.      *      in each direction
  81.      */
  82.     extra = extra2 = 0;
  83.     if ( w0-> winbox )
  84.         {
  85.         extra  = 1;
  86.         extra2 = 2;
  87.         }
  88.  
  89.  
  90.     l = (     (w0-> winleft)   -extra  );
  91.     r = ( l + (w0-> winxmax)   +extra2 );
  92.     t = (     (w0-> wintop)    -extra  );
  93.     b = ( t + (w0-> winymax)   +extra2 );
  94.  
  95.     movenum = r-l+1;    /* #bytes in each row */
  96.  
  97.     if ( hptr == NULL )
  98.         {
  99.         /* nothing saved -- just clear the area to black
  100.          * but rmemeber to clear out the window border as well.
  101.          */
  102.         save_attr = wgetattr();
  103.         wsetattr (BLACK);
  104.         wclearabs (l,t,r,b);
  105.         wsetattr(save_attr);
  106.  
  107.         return;        /*wrestore */
  108.         }    /* end of clearing window if not saved */
  109.  
  110.  
  111.     /* access heap element from expanded, ram or disk.
  112.      */
  113.     area = wheap_access ( hptr, 1 );
  114.  
  115.  
  116.     if ( wmode == 'T' )
  117.         {
  118.         movenum *= 2;
  119.  
  120.  
  121.         for (    line_ptr  = wpage_ram + 2*80*( t ) + 2*( l );
  122.             t <= b;
  123.             ++t,  line_ptr += 2*80
  124.             )
  125.             {
  126.  
  127.             farmemcpy ( line_ptr, area, movenum );
  128.             area += movenum;
  129.  
  130.             }
  131.         /* end text-mode moving screen image */
  132.  
  133.         }
  134.  
  135. #ifndef TEXTONLY
  136.     else
  137.         {
  138.         /* restore graphics mode windows. put image function
  139.          * Don't use BGI putimage because 1) significantly slower
  140.          * 2) doesn't always work if you only wrote using wputc/wputs
  141.          * or wclear since BGI keeps a 'buffer' and if the buffer
  142.          *    thinks it contains the screen
  143.          *    it will avoid going direclty to the
  144.          *    EGA registers,
  145.          *    so getimage/putimage will destroy the windows.
  146.          */
  147.  
  148.  
  149.  
  150.         /* graphics mode restore.
  151.          *
  152.          */
  153.  
  154.         /* convert to pixel co-ords only for counting rows */
  155.         t_pix  = t*wpychar;
  156.         b_pix  = (b+1) * wpychar;  /* one beyond last row */
  157.  
  158.  
  159.  
  160.         /* put image */
  161.  
  162.         switch ( wmonitor )
  163.             {
  164.         case ( 'H'):
  165.             /* NOTE addressing hercules graphics ram:
  166.              *    l, t are 'text-mode' addresses.
  167.              *    720 pixels/row, wpxchar pixels per 'x' incr
  168.              *    so 1st factor = wxabsmax = chars per row
  169.              *    divide wpychar by 4(=# herc banks) =
  170.              *        gives #of sets of banks (4 pixel rows each)
  171.              *    wpxchar/8 =1 always, included for clarity.
  172.              *
  173.              *    because charsize is mult of 4,
  174.              *        whbank starts at 0;
  175.              *
  176.              *    Note that t, b have been converted to pixels,
  177.              *            so don't need to multiply by wpychar again.
  178.              *    However, r & b still count text columns,
  179.              *          not pixels
  180.              */
  181.             base    =  wpage_ram
  182.                 + ( (720/wpxchar)*(t_pix/4) ) + l;
  183.  
  184.  
  185.             for ( hn = 0; t_pix < b_pix;  ++t_pix, hn += 0x2000 )
  186.                 {
  187.                 /* loop iterates once per row
  188.                  */
  189.                 if ( hn == 0x8000 )
  190.                     {
  191.                     /* finished one set of 4 banks,
  192.                      * move up to next tier.
  193.                      */
  194.                     hn = 0;
  195.                     base += 90;
  196.                     }
  197.  
  198.                 #ifdef __TURBOC__ 
  199.                     /*  move data from save area to screen
  200.                      */
  201.                     farmemcpy ( base+hn, area, movenum );
  202.                 #else
  203.                     /* Microsoft C - preprocessor generates incorrect code
  204.                      * in the farmemcpy for small model --
  205.                      * needs an 'intermediary' ptr to get it right.
  206.                      */
  207.                     msc_ptr = base+hn;
  208.                     farmemcpy ( msc_ptr, area, movenum );
  209.                 #endif        /* Microsoft fix */
  210.                 
  211.                 area += movenum;
  212.  
  213.                 }
  214.             break;       /* end hercules mode */
  215.  
  216.         case ( 'E' ):
  217.         case ( 'V' ):
  218.             EGA_OUT (1, EGA_ENABLE );
  219.             /* how to put point = EGA_OUT(3, putmode)
  220.              *   0x18 = XOR  0x10 = OR  0x08 = AND
  221.              */
  222.  
  223.  
  224.             /* blacken window first
  225.              * so old contents don't show up underneath new ones.
  226.              */
  227.             save_attr = w0->winattr;
  228.             w0->winattr = BLACK;
  229.             wclearabs (l,t,r,b);
  230.             w0->winattr = save_attr;
  231.  
  232.  
  233.  
  234.             /* co-ord in screen buffer of top/left pixel
  235.              * note that t_pix & b_pix count pixel rows
  236.              * but r &b still count text (byte) rows
  237.              */
  238.  
  239.             base_save =
  240.             base = wpage_ram + ( wegarowsize * t_pix ) + l;
  241.             t_save = t_pix;
  242.  
  243.             EGA_OUT ( 3,  0x10 );    /* OR into existing bits */
  244.  
  245.  
  246.             for ( color = 1; color < 0x09; color <<= 1  )
  247.                 {
  248.  
  249.                 EGA_OUT ( 0,  color);   /* select color plane */
  250.  
  251.                 /* loop once per row */
  252.                 for (     base = base_save, t_pix = t_save;
  253.                     t_pix < b_pix;
  254.                     ++t_pix, base += 640/wpxchar )
  255.                     {
  256.                     for (    col = l, colptr =base;
  257.                         col <= r;
  258.                         ++col, ++colptr)
  259.                         {
  260.                         latch = *(colptr);
  261.  
  262.                         EGA_OUT ( 8, *area );
  263.  
  264.                         *(colptr)  = *( area++ );
  265.                         }
  266.  
  267.                     }    /* end for each rows */
  268.                 }/* end loop for each color */
  269.  
  270.                 /* reset EGA */
  271.                 EGA_OUT (1, EGA_ENABLE);
  272.                 EGA_OUT (0,0);            /* BLACK */
  273.                 EGA_OUT (8, 0xff);              /* all bits */
  274.  
  275.  
  276.                 break;
  277.                 }     /* end switch (wgdriver) */
  278.  
  279.  
  280.         /* end of put image */
  281.  
  282.         }
  283. #endif    /* ifdef TEXTONLY - end of graphics mode wrestore */
  284.  
  285.  
  286.  
  287.     wheap_deaccess ( hptr, 0 );
  288.  
  289.     return;    /* wrestore */
  290.     }
  291.  
  292. /*----------------------  end of WRESTORE.C -------------------------*/
  293.  
  294.  
  295.