home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / SET_MODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-02-04  |  4.2 KB  |  125 lines

  1. /* set_mode.c -- main program to set video mode on the IBM PC
  2.  
  3.        **************** Copyright 1984 by Vince Taylor ******************
  4.  
  5.       USAGE
  6.  
  7.        To set the video mode on the IBM PC and to initialize the
  8.        color/graphics display adapter when both adapters are installed.
  9.  
  10.       FUNCTION
  11.  
  12.        Requests user to enter mode code.
  13.  
  14.        Places proper value in bits 5 and 6 of EQUIP_FLAG, located at
  15.        40:10, in the BIOS data area by first reading EQUIP_FLAG and
  16.        then replacing bits 5 & 6 (out of 8) with the following values:
  17.  
  18.                Mode         Bits 6 and 5         Display
  19.  
  20.              0 - 1              0   1          (40x25)
  21.              2 - 3              1   0          (80x25)
  22.              4 - 6              1   0          graphics
  23.                7              1   1          (80x25)
  24.  
  25.         The flag value determines the initial display mode, which
  26.         is always black and white, but may be either 40 or 80
  27.         columns.  In this routine, we will never see the initial
  28.         (default) display because we immediately set the mode to
  29.         the one requested by the user.    The equipment flag is
  30.         relevant because it is used by the BIOS mode-set routine
  31.         and will create an error unless properly set. (It also seems
  32.         to be used by some other part of BIOS, because as soon
  33.         as the flag value is changed to indicate another type
  34.         of display card, before the mode is formally
  35.         changed, output disappears from the currently active
  36.         screen.)
  37.  
  38.         The flag value needs to be changed if we want to change
  39.         from the mono adapter to the color/graphics adapter,
  40.         because the IBM BIOS always sets the flag for the mono card
  41.         (mode 7) if both are installed, and the value of the flag
  42.         is used by the BIOS mode- set routine (INT 10H, function 0)
  43.         to determine whether the mono or color/graphics board
  44.         addresses are to be used.  Thus, to allow switching from
  45.         one adapter to the other, we change the flag setting to
  46.         indicate the adapter card corresponding to the mode
  47.         selected.  (We could use either 01 binary or 10 binary for
  48.         bits 5 and 6 for all color/graphics display modes.  We use
  49.         the two value simply to remain consistent with parameter
  50.         values used by the BIOS for the initialization sequence.)
  51.  
  52.        Calls VID_INT with AH = 0 and AL = mode value to set the
  53.        display mode to the one selected by the user.
  54.  
  55.       CALL
  56.  
  57.        set_mode()
  58.  
  59.       RETURNS
  60.  
  61.        = mode value.
  62.  
  63.       CAUTIONS
  64.  
  65.        This program will NOT operate properly only under UNIX systems
  66.        since it makes use of hardware features of MSDOS systems.
  67.  
  68. */
  69.  
  70. /* #define WN_DEBUG          Commented out when debugged              */
  71. #include <wfc.h>
  72. #include <wfc_glob.h>
  73.  
  74. main()
  75. {
  76.     int mode;
  77.     int kval;
  78.     WINDOW wn;                /*window for display              */
  79.  
  80.     init_wfc();             /*initialize the WFC system          */
  81.     defs_wn(&wn,0,0,20,40,&bdr_dln);    /*initialize window              */
  82.     sav_wi(&wn);
  83.     set_wn(&wn);
  84.     for(;;)
  85.     {
  86.     cl_wn(&wn);
  87.     v_st("Modes available for selection are:\n\n", &wn);
  88.     v_st("         Mode     Mode Number \n", &wn);
  89.     v_st("     Graphics Board       \n", &wn);
  90.     v_st("      40x25 B&W         0 \n", &wn);
  91.     v_st("      40x25 Color       1 \n", &wn);
  92.     v_st("      80x25 B&W         2 \n", &wn);
  93.     v_st("      80x25 Color       3 \n", &wn);
  94.     v_st("   Graphics Modes\n"         , &wn);
  95.     v_st("     320x200 Color      4 \n", &wn);
  96.     v_st("     320x200 B&W        5 \n", &wn);
  97.     v_st("     640x200 B&W        6 \n", &wn);
  98.     v_st("   Monochrome Board     7 \n\n", &wn);
  99.     wn.att = NORMAL + HIGH_INT;
  100.     v_st("Please type mode number:  ", &wn);
  101.     pl_csr(&wn);
  102.     mode = ki();
  103.     wn.c = 0;            /*put cs at beginning of row          */
  104.     v_qch(' ',wn.ce - wn.cb + 1, &wn);  /*erase row (cs does not move)    */
  105.     v_st("Mode selected is ",&wn);    /*rewrite message                 */
  106.     v_rw(mode,1,&wn);
  107.     wn.att = NORMAL;
  108.     v_st("\n\nPress Escape to cancel entry, any other key to proceed.", &wn);
  109.     pl_csr(&wn);
  110.     if((kval =ki()) == 27) continue;
  111.     if(kval == -1)            /*control-break exit              */
  112.     {
  113.         unset_wn(&wn);
  114.         mv_csr(23,0,&wn0);
  115.         exit(0);
  116.     }
  117.     if((mode -= 48) >= 0 && mode <= 7)
  118.         break;            /*legitimate number, continue          */
  119.     wn.c = 0;            /*else go back and try again          */
  120.     }
  121.     unsav_wi(&wn);
  122.     vid_mode(mode);
  123.     return(0);
  124. }
  125.