home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk10 / apps / setega / setega.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.7 KB  |  139 lines

  1.  /*** SETEGA.C    OS/2 demo program to switch EGA between 25- and 43- line modes
  2.   *
  3.   *   SETEGA accepts one parameter, which must be either "25" or "43".
  4.   *   Too few or too many parameters, or a parameter other than the two
  5.   *   specified above, will result in an error message and termination
  6.   *   with no action taken.
  7.   *
  8.   *   This program will work only on machines equipped with a standard EGA.
  9.   *
  10.   *   SETEGA functions as follows:
  11.   *
  12.   *     1) Check parameters
  13.   *
  14.   *     2) Clear the screen, using the VIOSCROLLUP function as described
  15.   *        in the CLRSCR example elsewhere in these bulletin boards
  16.   *
  17.   *     3) Get current mode information using VIOGETMODE
  18.   *
  19.   *         extern unsigned far pascal VIOGETMODE (
  20.   *            struct ModeData far *,
  21.   *            unsigned );
  22.   *
  23.   *        This call fills a data structure of type
  24.   *
  25.   *         struct ModeData {
  26.   *            unsigned length;
  27.   *            unsigned char type;
  28.   *            unsigned char color;
  29.   *            unsigned col;
  30.   *            unsigned row;
  31.   *            unsigned hres;
  32.   *            unsigned vres;
  33.   *            };
  34.   *
  35.   *        whose address we pass in the first parameter. The second
  36.   *        parameter is the VIO handle, a reserved word of zeros.
  37.   *
  38.   *     4) We leave all these fields as they are except "row", the number
  39.   *        of alphanumeric rows for this mode. This is changed to the
  40.   *        value specified in our parameter.
  41.   *
  42.   *     5) VIOSETMODE is now used to set the mode.
  43.   *
  44.   *         extern unsigned far pascal VIOSETMODE (
  45.   *            struct ModeData far *,
  46.   *            unsigned );
  47.   *
  48.   *        This call has the same parameters as VIOGETMODE.
  49.   *        We are now set to the desired mode.
  50.   *
  51.   *     6) We then set the cursor to an appropriate size and shape. This is
  52.   *        done by filling in a structure of the type
  53.   *
  54.   *         struct CursorData {
  55.   *            unsigned cur_start;
  56.   *            unsigned cur_end;
  57.   *            unsigned cur_width;
  58.   *            unsigned cur_attribute;
  59.   *            };
  60.   *
  61.   *        with appropriate values, then calling VIOSETCURTYPE
  62.   *
  63.   *         extern unsigned far pascal VIOSETCURTYPE (
  64.   *            struct CursorData far *,
  65.   *            unsigned );
  66.   *
  67.   *        where the second parameter is again the VIO handle, 0.
  68.   *
  69.   *     7) Last, we set the cursor to the upper left hand corner of the
  70.   *        screen using VIOSETCURPOS.
  71.   *
  72.   *
  73.   *   Compile using the -Lp option; this program may be bound for use under
  74.   *   real mode.
  75.   */
  76.  
  77. #include <subcalls.h>
  78. #include <doscalls.h>
  79. #include <stdio.h>
  80.  
  81. void usage();
  82.  
  83. void main( argc, argv )
  84. int  argc;
  85. char *argv[];
  86. {
  87.  
  88.     struct  ModeData    modedata;
  89.  
  90.     struct  CursorData    cursordata;
  91.  
  92.     static char  buffer[2] = { 0x20, 0x07 };     /* scrolling fill character */
  93.                          /* for clearing the screen  */
  94.     if( argc != 2 )
  95.     usage(argv[0]);
  96.  
  97.     switch(atoi(argv[1])) {
  98.     case 43:
  99.         VIOSCROLLUP( 0, 0, -1, -1, -1, (char far *)buffer, 0 );
  100.         modedata.length = sizeof( modedata );
  101.         VIOGETMODE( &modedata, 0 );
  102.         modedata.row = 43;
  103.         VIOSETMODE( &modedata, 0 );
  104.         cursordata.cur_start = 7;
  105.         cursordata.cur_end = 7;
  106.         cursordata.cur_width = 1;
  107.         cursordata.cur_attribute = 0;
  108.         VIOSETCURTYPE( &cursordata, 0 );
  109.         VIOSETCURPOS( 0, 0, 0 );
  110.     break;
  111.     
  112.     case 25:
  113.         VIOSCROLLUP( 0, 0, -1, -1, -1, (char far *)buffer, 0 );
  114.         modedata.length = sizeof( modedata );
  115.         VIOGETMODE( &modedata, 0 );
  116.         modedata.row = 25;
  117.         VIOSETMODE( &modedata, 0 );
  118.         cursordata.cur_start = 12;
  119.         cursordata.cur_end = 13;
  120.         cursordata.cur_width = 1;
  121.         cursordata.cur_attribute = 0;
  122.         VIOSETCURTYPE( &cursordata, 0 );
  123.         VIOSETCURPOS( 0, 0, 0 );
  124.     break;
  125.  
  126.     default:
  127.         usage(argv[0]);
  128.     }
  129.     exit(0);
  130. }
  131.  
  132. void
  133. usage(p)
  134. char *p;
  135. {
  136.     printf( "usage: %s 25|43\n", p);
  137.     exit(1);
  138. }
  139.