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

  1. /*! winit ()
  2.  *    setup video modes.  Initialize window system for selected mode.
  3.  *      declare all the global variables for the window system.
  4.  *    NOTE: This function does not write to the video screen.
  5.  *          No future changes should write to video...
  6.  *         This allows for wdvinit (DeskView) version, planned for future release
  7.  *
  8.  */
  9.  
  10. #include  "wscreen.h"
  11. #include  "wsys.h"
  12.  
  13. #include <signal.h>
  14.  
  15.  
  16.  
  17.  
  18. /*! global variables
  19.  *
  20.  *  these are declared extern in the headers as externs for type checking
  21.  *    NOTE that this file conserves word alignment, regardless
  22.  *    of whether -a switch is on or off.
  23.  *    To do this, all declarations are in order: far *, long,  *,int, char.
  24.  */
  25.  
  26.  
  27.  
  28. /* pointers to start of video storage (different for each monitor),
  29.  *            current page  (different for each mode/monitor)
  30.  *            and offset from page 0 to page 1
  31.  */
  32. unsigned char far *wvideo_ram =  NULL;
  33. unsigned char far *wpage_ram  =  NULL;
  34.  
  35.  
  36.  
  37. WINDOW  *(w0) = NULL;
  38.  
  39. WINDOW  *(wfullscreen);
  40.  
  41.  
  42. char    *whelp_ptr = NULL;
  43.  
  44.  
  45.  
  46. /* keyboard trap routine and pipes.
  47.  */
  48. int (*wkeytrap)(int)     = NULL;
  49. int (*wpipein)(void)         = NULL;
  50. void        (*wpipeout)( int )     = NULL;
  51.  
  52.  
  53.  
  54.  
  55. struct WLOCATION wlocation = { 0, 0, WLOC_CENTER, 0 };
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. #ifndef TEXTONLY
  63.  
  64.     /* used only in graphics mode
  65.      */
  66.     #ifdef __TURBOC__
  67.         char         *wpath_BGI = "C:\\TC";     /* DOS path to BGI drivers */
  68.     #endif    /* TurboC location of BGI files */
  69.  
  70.  
  71.     int         wpxabsmax, wpyabsmax;     /* highest pixel numbers */
  72.     #define        wpxchar 8
  73.     #define        wpychar 8
  74.  
  75.     int    wegarowsize = 80;                    /* 100 for superVGA 800*600 */
  76.  
  77.  
  78. #endif    /* ! TEXTONLY */
  79.  
  80. char *whome_dir = "\0";        /* defualt is current dir */
  81.  
  82.  
  83. unsigned int      wpage_size = 0;
  84.  
  85. int        wxabsmax     = 79;
  86. int        wyabsmax      = 24;
  87. int        wtabwidth    =8;
  88.  
  89. /* cursor lines: high byte is start line, low byte is stop line.
  90.  * for CGA, change to 0x0607. Also change cursor size for 43- and 50-line modes
  91.  */
  92. unsigned int wcurscanln = 0x0C0D;        
  93.  
  94.  
  95.  
  96. /* mouse control structure
  97.  */
  98. WMOUSE wmouse = {0,0, 0,0,0,0, 0,0,0,0,  0,0,0,0 };
  99.  
  100.  
  101.  
  102. /* unget buffer
  103.  */
  104. int wunget_buffer = 0;
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. unsigned char     wmenuattr   = GREEN;
  113. unsigned char     wmenuboxattr= GREEN;
  114. unsigned char     whelpattr   = (CYAN<<4);
  115. unsigned char     wbuttonattr = 0x70;  /* reverse video */
  116.  
  117.  
  118.  
  119.  
  120.  
  121. char         wmonitor = 0x00;        /* H, V, E, or (text only) C */
  122. char         wega256  = 1;        /* 1= have 256k of RAM */
  123.  
  124. char         wmode;           /*  'T' or 'G' */
  125.  
  126.  
  127. const struct WBOX_PATTERN wbox[] =
  128.     {
  129.     /* NW, Hor, NE, SW, Vert, SE */
  130.        0,  0,  0,  0,  0,  0        /*0 NO_BORDER         */
  131.     ,218,196,191,192,179,217    /*1 SINGLE_BORDER    */
  132.     ,201,205,187,200,186,188     /*2 DOUBLE_BORDER    */
  133.     ,176,176,176,176,176,176    /*3 SPECKLE_BORDER    */
  134.     ,' ',' ',' ',' ',' ',' '    /*4 SOLID_BORDER    */
  135.  
  136.     ,213,205,184,212,179,190    /*5 MIXED2H1V_BORDER    */
  137.     ,214,196,183,211,186,189    /*6 MIXED1H2V_BORDER    */
  138.  
  139.     ,209,205,209,212,179,190        /*7 HANGING_BORDER    */
  140.     ,213,205,184,207,179,207    /*8 STANDUP_BORDER    */
  141.  
  142.     };
  143.  
  144.  
  145.  
  146.  
  147.  
  148. unsigned char    wlastpage =0;     /* number of supported pages in curr.mode */
  149. unsigned char   wnextpage =0;    /* display next window on indicated page */
  150. unsigned char   wneedpage =0;
  151.  
  152.  
  153.  
  154. /*---------------------------  end of GLOBALS --------------------*/
  155.  
  156.  
  157. static void cleanup (void);
  158.  
  159. static void closeall (void);
  160.  
  161.  
  162. void    winit ( char newmode)
  163.     {
  164.  
  165.  
  166.     PSEUDOREGS
  167.  
  168.  
  169.  
  170. #ifdef TEXTONLY
  171.  
  172.     if ( newmode == 'G' )
  173.         {
  174.         perror ("TEXT ONLY ");
  175.         exit ('W');
  176.         }
  177. #endif     /* TEXTONLY */
  178.  
  179.  
  180.  
  181.     if ( ! wmonitor )
  182.         {
  183.         /* first call to window program */
  184.         wgetmon();
  185.  
  186.  
  187.  
  188.         /* detect enhanced keyboard
  189.          */
  190.         wkbd_init ();
  191.  
  192.         /* detect expanded memory, setup disk heap
  193.          */
  194.         wheap_init ();
  195.  
  196.  
  197.         /* ignore control break handling */
  198.         if ( signal(SIGINT, SIG_IGN) == SIG_ERR )
  199.             {
  200.             /* installing signal handler failed */
  201.             perror ("ctrl-c");
  202.             exit('W');
  203.             }
  204.  
  205.  
  206.         /* stack exit routines - restorecrtmode, turn on cursor,
  207.          *
  208.          */
  209.         atexit (cleanup);
  210.  
  211.  
  212.         }
  213.     else
  214.         {
  215.         /* This is a call to change screen mode -
  216.          * first have to free up all the window storage from
  217.          * last mode
  218.          */
  219.         closeall();
  220.         }
  221.  
  222.  
  223.     /* disable pages - see winit_pages() to enable pages.
  224.      */
  225.     wnextpage = wlastpage = 0;
  226.     
  227.     /* have to place HERCULES monitor in FULL mode 
  228.      * before writing any info to screen, 
  229.      * if second video page is needed.
  230.      */
  231.     if ( (wmonitor == 'H') && wneedpage )
  232.         {
  233.         outp ( 0x3BF, 0x02 );    /* FULL mode */
  234.         }
  235.  
  236.  
  237.  
  238.     if ( newmode == 'T' )
  239.         {
  240.  
  241.         #ifndef TEXTONLY
  242.             if (wmode == 'G')
  243.                 {
  244.                 wtextmode ();    /* restore CRT */
  245.                 }
  246.         #endif
  247.  
  248.  
  249.  
  250.         wvideo_ram = EGA_TEXT_RAM;
  251.  
  252.         if ( wmonitor == 'H' || wmonitor == 'M' )
  253.             {
  254.             wvideo_ram = HERC_TEXT_RAM;
  255.             }
  256.         else
  257.         if ( wmonitor == 'C' )
  258.             {
  259.             wcurscanln = 0x0607;        /* cursor size for CGA monitors */
  260.             }
  261.             
  262.         wpage_ram = wvideo_ram;
  263.         wxabsmax = 79;
  264.         wyabsmax = 24;
  265.         wmode = 'T';
  266.  
  267.         } /* end initializing newmode = T */
  268.  
  269. #ifndef TEXTONLY
  270.     /* graphics mode init routine */
  271.  
  272.     else    /*( newmode == 'G' ) */
  273.         {
  274.         wmode = 'G';
  275.  
  276.         if ( wmonitor == 'H' )
  277.             {
  278.             wvideo_ram = HERC_GRAPH_RAM;
  279.             }
  280.         else
  281.             {
  282.             wvideo_ram = EGA_GRAPH_RAM;    
  283.             }
  284.  
  285.         wpage_ram = wvideo_ram;                    /* start on page 0 */
  286.  
  287.         wgraphmode ();
  288.         
  289.         wegarowsize = (wpxabsmax+1) / 8;        /* bytes per row */
  290.  
  291.         }    /* end initializing newmode = 'G' */
  292.  
  293. #endif /* end ifdef TEXTONLY */
  294.  
  295.     wfullscreen = wdefine
  296.               (0,0, wxabsmax+1, wyabsmax+1, 0x07, NO_BORDER, 0);
  297.  
  298.     wmouse_init();
  299.  
  300.     return;     /* end winit */
  301.  
  302.     }
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. /*! cleanup ();
  316.  *    automatic cleanup routines - restore the screen, cursor, etc...
  317.  *
  318.  */
  319.  
  320. static void cleanup (void)
  321.         {
  322.  
  323.         winit ('T');
  324.  
  325.         wgoto (0, wyabsmax-1);
  326.         wsetattr (0x07);
  327.  
  328.  
  329.         wcursor (ON);
  330.  
  331.  
  332.         /* restore ctrl-c checking */
  333.         if ( signal(SIGINT, SIG_DFL) == SIG_ERR )
  334.             {
  335.             perror ("ctrl-c");
  336.             exit(99);
  337.             }
  338.  
  339.         /* cleanup disk heap and release expanded memory
  340.          */
  341.         wheap_freeall ();
  342.  
  343.         return;
  344.         }
  345.  
  346.  
  347.  
  348. static void closeall (void)
  349.     {
  350.     WINDOW *wp;
  351.     WBUTTON  *b, *nb;
  352.  
  353.     while ( w0 )
  354.         {
  355.         /* free screen save area storage
  356.          */
  357.         if ( w0-> winsave )
  358.             {
  359.             wheap_free ( w0-> winsave );
  360.             }
  361.  
  362.  
  363.         /* free button storage
  364.          */
  365.         for ( b = w0-> winbutton; b; b = nb )
  366.             {
  367.             nb = b->Bchain;
  368.  
  369.             free (b);
  370.             }
  371.  
  372.  
  373.  
  374.  
  375.  
  376.         wp  = w0;
  377.         w0 = w0-> winchain;
  378.  
  379.         free (wp);
  380.  
  381.         }
  382.  
  383.  
  384.     return;    /* closeall */
  385.     }
  386.     
  387.     /*---------------- end of WINIT.C ----------------------*/