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

  1. /*! wsetvisualpage() and winit_pages()
  2.  *
  3.  *    support for multiple video pages.
  4.  *
  5.  *    functions like borland's setvisualpage,
  6.  *    but runs in either text or graphics modes.
  7.  *
  8.  *     also, this routine turns off the mouse on high pages in Hercules
  9.  *        ( some mouse drivers can handle Hercules monitor page 1,
  10.  *          but not all can, and technique is non-documented
  11.  *          hence dangerous )
  12.  *    restores the mouse when page is switched back to page 0.
  13.  *
  14.  *    pass a page number,
  15.  *    that page will be displayed.
  16.  *
  17.  *    Window output will still be written to the current window
  18.  *     which may or moy not be on the displayed page
  19.  *
  20.  *    If the requested page is out of bounds,
  21.  *    the closest fit (0 or highest page) is used
  22.  *
  23.  *
  24.  */
  25.  
  26.  
  27. #include "wscreen.h"
  28. #include "wsys.h"
  29.  
  30.  
  31.  
  32. static unsigned char mouse_present =0;
  33.  
  34.  
  35. /* METHOD:
  36.  *    Hercules: hercules control port at 0x3B8 contains:
  37.  *        bit 7 (=hi, 0x80) = page assignment 0=0, 1=1
  38.  *        bit 5 ( 0x20 )    = blink enable (always on).
  39.  *                  3 ( 0x08 )    = video enable/disable
  40.  *            1 ( 0x02 )    = mode  ( 1= graphics )
  41.  *            0 ( 0x01 )    = hi-res control (always on)
  42.  *            unfortunately the port is write-only, so
  43.  *         need to construct appropriate bit values before setting.
  44.  *    EGA/VGA:
  45.  *        ROM BIOS sets displayed papge in either text or graphics mode
  46.  */
  47. #define  HCONTROL 0x29    /* blink enable, video enabel, hi-res all ON */
  48.  
  49.  
  50. void wsetvisualpage (int page)
  51.     {
  52.     char herc_byte;        /* hercules control byte */
  53.  
  54.  
  55.  
  56.     PSEUDOREGS
  57.  
  58.  
  59.     if (page <0)        page=0;
  60.     if (page >wlastpage)     page = wlastpage;
  61.  
  62.  
  63.     if ( wmode == 'G' || wmonitor == 'H' )
  64.         {
  65.         /* in EGA graphics or any mode of hercules
  66.          * turn off the mouse on higher pages.
  67.          *
  68.          * MOUSE driver only supports higher pages
  69.          * in text mode on EGA/VGA
  70.          */
  71.         wmouse.wms_present = ( page ) ? 0 : mouse_present;
  72.         }
  73.  
  74.  
  75.  
  76.  
  77.     if (wmonitor  == 'H')
  78.         {
  79.  
  80.         /* build hercules control byte to set page.
  81.          * without affecting graphics mode, blink, or video enable
  82.          */
  83.         herc_byte  =  HCONTROL;
  84.  
  85.         if ( page  == 1 )
  86.             {
  87.             herc_byte |= 0x80;
  88.             }
  89.  
  90.         if ( wmode == 'G' )
  91.             {
  92.             herc_byte |= 0x02;
  93.             }
  94.  
  95.  
  96.         outp ( 0x3B8, herc_byte );
  97.  
  98.         }
  99.         else
  100.         {
  101.         /* EGA or VGA */
  102.  
  103.         _AL = page;
  104.         _AH = 5;
  105.         INTERRUPT (0x10);
  106.  
  107.         }
  108.  
  109.     return;    /* wsetvisualpage() */
  110.     }
  111.  
  112. static char installed_atexit = 0;
  113. static void restore_pages_atexit (void);
  114.  
  115. /* winit_pages ()
  116.  *
  117.  */
  118. void winit_pages ( char mode )
  119.     {
  120.     int n, x, y;
  121.  
  122.  
  123.  
  124.  
  125.     wneedpage = ON;
  126.     winit ( mode );
  127.  
  128.     if ( ! installed_atexit )
  129.         {
  130.         /* only install the atexit function once,
  131.          * to make sure system is on page 0 when terminates
  132.          */
  133.         installed_atexit = 1;
  134.          atexit ( restore_pages_atexit );
  135.         }
  136.  
  137.  
  138.     if ( mode == 'T' )
  139.         {
  140.  
  141.         /* setup default for EGA/VA
  142.          */
  143.         wpage_size = 4096;
  144.         wlastpage  = 7;        /* pages 0,1,2,3... */
  145.  
  146.         if ( wmonitor == 'H' )
  147.             {
  148.             wpage_size = 0x8000;
  149.             wlastpage  = 1;        /* enable pages 0 & 1 */
  150.             }
  151.         else
  152.         if ( wmonitor == 'M' )
  153.             {
  154.             wlastpage =0;    /* disable paging */
  155.             }
  156.  
  157.  
  158.         } /* end initializing newmode = T */
  159.  
  160. #ifndef TEXTONLY
  161.     /* graphics mode init routine */
  162.  
  163.     else    /*( mode == 'G' ) */
  164.         {
  165.         wpage_size = 0x8000;
  166.         wlastpage  = 1;
  167.         }    /* end initializing newmode = 'G' */
  168.  
  169. #endif /* end ifdef TEXTONLY */
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.     /* clear video RAM in the higher memory pages
  178.      */
  179.     x = wxabsmax;
  180.     y = wyabsmax;
  181.     for ( n=1; n <= wlastpage; ++n )
  182.         {
  183.         wnextpage = n;
  184.         wdefine (0,0, x,y, 0x07, NO_BORDER, 0);
  185.         wclear();
  186.         wabandon();
  187.         }
  188.     wnextpage = 0;
  189.  
  190.     /* save mouse status so it can be turned on/off
  191.      * in hercules monitors when not on page 0
  192.      */
  193.     mouse_present = wmouse.wms_present;
  194.  
  195.     return;        /* winit_pages () */
  196.     }
  197.  
  198.  
  199. static void restore_pages_atexit (void)
  200.     {
  201.     wsetvisualpage (0);
  202.     
  203.     return;        /* restore_pages_atexit */
  204.     }