2 * Copyright (c) 1992,1993,1994 Hellmuth Michaelis and Joerg Wunsch
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by
17 * Hellmuth Michaelis and Joerg Wunsch
18 * 4. The name authors may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/usr.sbin/pcvt/scon/scon.c,v 1.5.6.1 2001/05/12 10:11:42 kris Exp $
33 * $DragonFly: src/usr.sbin/pcvt/scon/Attic/scon.c,v 1.3 2004/03/24 17:46:23 cpressey Exp $
37 "@(#)scon.c, 3.20, Last Edit-Date: [Sun Sep 25 12:33:21 1994]";
39 /*---------------------------------------------------------------------------*
43 * -hm moving fd for default device from 1 -> 0 for such things
44 * as "scon -p list | more" to be possible
45 * (reported by Gordon L. Burditt, gordon@sneaky.lonestar.org)
46 * -hm adding option "a" for just returning the type of video adaptor
47 * -hm removing explicit HGC support, same as MDA ...
48 * -hm vga type/family/132col support info on -l
49 * -hm force 24 lines in DEC 25 lines mode and HP 28 lines mode
50 * -hm fixed bug with 132 column mode display status display
51 * -jw added 132/80 col mode switching
52 * -hm removed -h flag, use -? now ... ;-)
54 * -hm Cirrus chipsets support from Onno van der Linden
55 * -hm -m option, display monitor type
56 * -hm bugfix, scon -c <screen-num> cleared dest screen, fixed
58 *---------------------------------------------------------------------------*/
63 #include <machine/pcvt_ioctl.h>
84 struct screeninfo screeninfo;
93 static struct rgb palette[NVGAPEL] = {
94 { 0x00, 0x00, 0x00, 0}, /* 0 - black */
95 { 0x00, 0x00, 0x2a, 0}, /* 1 - blue */
96 { 0x00, 0x2a, 0x00, 0}, /* 2 - green */
97 { 0x00, 0x2a, 0x2a, 0}, /* 3 - cyan */
98 { 0x2a, 0x00, 0x00, 0}, /* 4 - red */
99 { 0x2a, 0x00, 0x2a, 0}, /* 5 - magenta */
100 { 0x2a, 0x2a, 0x00, 0}, /* 6 */
101 { 0x2a, 0x2a, 0x2a, 0}, /* 7 - lightgray */
102 { 0x00, 0x00, 0x15, 0}, /* 8 */
103 { 0x00, 0x00, 0x3f, 0}, /* 9 */
104 { 0x00, 0x2a, 0x15, 0}, /* 10 */
105 { 0x00, 0x2a, 0x3f, 0}, /* 11 */
106 { 0x2a, 0x00, 0x15, 0}, /* 12 */
107 { 0x2a, 0x00, 0x3f, 0}, /* 13 */
108 { 0x2a, 0x2a, 0x15, 0}, /* 14 */
109 { 0x2a, 0x2a, 0x3f, 0}, /* 15 */
110 { 0x00, 0x15, 0x00, 0}, /* 16 */
111 { 0x00, 0x15, 0x2a, 0}, /* 17 */
112 { 0x00, 0x3f, 0x00, 0}, /* 18 */
113 { 0x00, 0x3f, 0x2a, 0}, /* 19 */
114 { 0x2a, 0x15, 0x00, 0}, /* 20 - brown */
115 { 0x2a, 0x15, 0x2a, 0}, /* 21 */
116 { 0x2a, 0x3f, 0x00, 0}, /* 22 */
117 { 0x2a, 0x3f, 0x2a, 0}, /* 23 */
118 { 0x00, 0x15, 0x15, 0}, /* 24 */
119 { 0x00, 0x15, 0x3f, 0}, /* 25 */
120 { 0x00, 0x3f, 0x15, 0}, /* 26 */
121 { 0x00, 0x3f, 0x3f, 0}, /* 27 */
122 { 0x2a, 0x15, 0x15, 0}, /* 28 */
123 { 0x2a, 0x15, 0x3f, 0}, /* 29 */
124 { 0x2a, 0x3f, 0x15, 0}, /* 30 */
125 { 0x2a, 0x3f, 0x3f, 0}, /* 31 */
126 { 0x15, 0x00, 0x00, 0}, /* 32 */
127 { 0x15, 0x00, 0x2a, 0}, /* 33 */
128 { 0x15, 0x2a, 0x00, 0}, /* 34 */
129 { 0x15, 0x2a, 0x2a, 0}, /* 35 */
130 { 0x3f, 0x00, 0x00, 0}, /* 36 */
131 { 0x3f, 0x00, 0x2a, 0}, /* 37 */
132 { 0x3f, 0x2a, 0x00, 0}, /* 38 */
133 { 0x3f, 0x2a, 0x2a, 0}, /* 39 */
134 { 0x15, 0x00, 0x15, 0}, /* 40 */
135 { 0x15, 0x00, 0x3f, 0}, /* 41 */
136 { 0x15, 0x2a, 0x15, 0}, /* 42 */
137 { 0x15, 0x2a, 0x3f, 0}, /* 43 */
138 { 0x3f, 0x00, 0x15, 0}, /* 44 */
139 { 0x3f, 0x00, 0x3f, 0}, /* 45 */
140 { 0x3f, 0x2a, 0x15, 0}, /* 46 */
141 { 0x3f, 0x2a, 0x3f, 0}, /* 47 */
142 { 0x15, 0x15, 0x00, 0}, /* 48 */
143 { 0x15, 0x15, 0x2a, 0}, /* 49 */
144 { 0x15, 0x3f, 0x00, 0}, /* 50 */
145 { 0x15, 0x3f, 0x2a, 0}, /* 51 */
146 { 0x3f, 0x15, 0x00, 0}, /* 52 */
147 { 0x3f, 0x15, 0x2a, 0}, /* 53 */
148 { 0x3f, 0x3f, 0x00, 0}, /* 54 */
149 { 0x3f, 0x3f, 0x2a, 0}, /* 55 */
150 { 0x15, 0x15, 0x15, 0}, /* 56 - darkgray */
151 { 0x15, 0x15, 0x3f, 0}, /* 57 - lightblue */
152 { 0x15, 0x3f, 0x15, 0}, /* 58 - lightgreen */
153 { 0x15, 0x3f, 0x3f, 0}, /* 59 - lightcyan */
154 { 0x3f, 0x15, 0x15, 0}, /* 60 - lightred */
155 { 0x3f, 0x15, 0x3f, 0}, /* 61 - lightmagenta */
156 { 0x3f, 0x3f, 0x15, 0}, /* 62 - yellow */
157 { 0x3f, 0x3f, 0x3f, 0}, /* 63 - white */
158 { 0x00, 0x00, 0x00, 0} /* 64 ... - empty */
161 static struct colname {
180 {"lightmagenta", 61},
183 /* must be terminator: */ {(const char *)NULL, 0}
187 static void usage(void);
188 static void printadaptor(int);
189 static void printmonitor(int);
190 static void printinfo(int);
191 static void parsepopt(char *arg, unsigned *idx,
192 unsigned *r, unsigned *g, unsigned *b);
193 static void printpalette(int fd);
196 main(int argc, char **argv)
205 while( (c = getopt(argc, argv, "ac:d:f:HVlms:t:vp:18")) != -1)
222 current = atoi(optarg);
244 if (!strncmp(optarg, "25", 2))
246 else if(!strncmp(optarg, "28", 2))
248 else if(!strncmp(optarg, "35", 2))
250 else if(!strncmp(optarg, "40", 2))
252 else if(!strncmp(optarg, "43", 2))
254 else if(!strncmp(optarg, "50", 2))
263 if(!strcmp(optarg, "list"))
266 errx(2, "-p list is mutual exclusive with other -p options");
269 else if(!strcmp(optarg, "default"))
272 errx(2, "multiple -p default not allowed");
275 unsigned idx, r, g, b;
278 errx(2, "-p default and -p i,r,g,b ambiguous");
280 parsepopt(optarg, &idx, &r, &g, &b);
282 errx(2, "index %u in -p option out of range", idx);
286 palette[idx].dothis = 1;
292 timeout = atoi(optarg);
310 if((pflag == 1) && (hflag == 1))
313 if(dflag == -1 && lflag == -1 && current == -1 && pflag == -1 &&
314 hflag == -1 && res == -1 && Pflag == 0 && tflag == 0 && fflag == -1
315 && colms == 0 && mflag == -1)
323 printf("using current device\n");
324 fd = DEFAULTFD; /* -hm, Feb 12 1993 */
328 if((fd = open(device, O_RDWR)) == -1)
329 err(1, "ERROR opening %s", device);
331 printf("using device %s\n",device);
334 if(aflag == 1) /* return adaptor type */
340 if(mflag == 1) /* return monitor type */
346 if(lflag == 1) /* list information */
349 printf("processing option -l, listing screen info\n");
354 if(tflag) /* set screen saver timeout */
359 "processing option -t, setting screen saver timeout: "
362 printf("new timeout = %d s\n", timeout);
364 printf("turned off\n");
367 if(ioctl(fd, VGASCREENSAVER, &timeout) < 0)
369 warn("ioctl(VGASCREENSAVER)");
370 fprintf(stderr, "Check the driver, the screensaver is probably not compiled in!\n");
379 printf("Setting number of columns to %d\n", colms);
380 if(ioctl(fd, VGASETCOLMS, &colms) < 0)
381 err(2, "ioctl(VGASETCOLMS)");
387 /* listing VGA palette */
389 printf("processing option -p list, "
390 "listing VGA palette\n");
400 /* setting VGA palette */
402 printf("processing option -p, setting VGA palette%s\n",
403 Pflag == 2? " to default": "");
405 for(idx = 0; idx < NVGAPEL; idx++)
406 if(Pflag == 2 || palette[idx].dothis)
410 p.r = palette[idx].r;
411 p.g = palette[idx].g;
412 p.b = palette[idx].b;
413 if(ioctl(fd, VGAWRITEPEL, (caddr_t)&p) < 0)
414 err(2, "ioctl(fd, VGAWRITEPEL)");
419 screeninfo.screen_no = -1; /* We are using fd */
420 screeninfo.current_screen = current;
421 screeninfo.pure_vt_mode = -1;
422 screeninfo.screen_size = res;
423 screeninfo.force_24lines = -1;
425 if(current != -1) /* set current screen */
428 printf("processing option -c, setting current screen to %d\n",current);
430 if(ioctl(1, VGASETSCREEN, &screeninfo) == -1)
431 err(1, "ioctl VGASETSCREEN failed");
438 printf("processing option -V, setting emulation to pure VT220\n");
439 screeninfo.pure_vt_mode = M_PUREVT;
444 printf("processing option -H, setting emulation to VT220 + HP Labels\n");
445 screeninfo.pure_vt_mode = M_HPVT;
450 printf("no change in terminal emulation\n");
456 printf("no change in screen resolution\n");
457 else if(res == SIZ_25ROWS)
458 printf("change screen resolution to 25 lines\n");
459 else if(res == SIZ_28ROWS)
460 printf("change screen resolution to 28 lines\n");
461 else if(res == SIZ_35ROWS)
462 printf("change screen resolution to 35 lines\n");
463 else if(res == SIZ_40ROWS)
464 printf("change screen resolution to 40 lines\n");
465 else if(res == SIZ_43ROWS)
466 printf("change screen resolution to 43 lines\n");
467 else if(res == SIZ_50ROWS)
468 printf("change screen resolution to 50 lines\n");
471 if(fflag == 1) /* force 24 lines on/off */
473 if(!strcmp(onoff, "on"))
477 else if(!strcmp(onoff, "off"))
483 fprintf(stderr,"you must specify 'on' or 'off' with -f option!\n");
487 screeninfo.force_24lines = fflag;
489 if(ioctl(fd, VGASETSCREEN, &screeninfo) == -1)
490 err(1, "ioctl VGASETSCREEN failed");
493 printf("successful execution of ioctl VGASETSCREEN!\n");
500 fprintf(stderr,"\nscon - screen control utility for the pcvt video driver\n");
501 fprintf(stderr,"usage: scon -a -l -m -v -c [n] -d [dev] -f [on|off] -V -H -s [n]\n");
502 fprintf(stderr,"usage: scon -p [default | list | i,r,g,b] | -t [sec] | -1 | -8\n");
503 fprintf(stderr," -a list video adaptor type (MDA,CGA,EGA or VGA)\n");
504 fprintf(stderr," -c <screen no> switch current virtual screen to <screen no>\n");
505 fprintf(stderr," -d <device> set parameters(-V|-H|-s) for virtual device\n");
506 fprintf(stderr," -f <on|off> force 24 lines in VT 25 lines and HP 28 lines mode\n");
507 fprintf(stderr," -H set VT220/HP emulation mode for a virtual screen\n");
508 fprintf(stderr," -l list current parameters for a virtual screen\n");
509 fprintf(stderr," -m report monitor type (MONO/COLOR)\n");
510 fprintf(stderr," -p default set default VGA palette\n");
511 fprintf(stderr," -p list list current VGA palette\n");
512 fprintf(stderr," -p <i,r,g,b> set VGA palette entry i to r/g/b\n");
513 fprintf(stderr," -p <name,r,g,b> set VGA palette entry for color name to r/g/b\n");
514 fprintf(stderr," -s <lines> set 25, 28, 35, 40, 43 or 50 lines for a virtual screen\n");
515 fprintf(stderr," -t <timeout> set screen saver timeout [seconds]\n");
516 fprintf(stderr," -1 set 132 columns mode\n");
517 fprintf(stderr," -8 set 80 columns mode\n");
518 fprintf(stderr," -v verbose mode\n");
519 fprintf(stderr," -V set pure VT220 emulation for a virtual screen\n");
520 fprintf(stderr," -? display help (this message)\n\n");
527 if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1)
528 err(1, "ioctl VGAGETSCREEN failed");
529 switch(screeninfo.adaptor_type)
532 case UNKNOWN_ADAPTOR:
557 if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1)
558 err(1, "ioctl VGAGETSCREEN failed");
559 switch(screeninfo.monitor_type)
578 static char *vga_tab[] = {
615 return(vga_tab[number]);
619 vga_family(int number)
621 static char *vga_tab[] = {
630 return(vga_tab[number]);
636 if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1)
637 err(1, "ioctl VGAGETSCREEN failed");
639 printf( "\nVideo Adaptor Type = ");
641 switch(screeninfo.adaptor_type)
644 case UNKNOWN_ADAPTOR:
645 printf("UNKNOWN Video Adaptor\n");
649 printf("MDA - Monochrome Display Adaptor\n");
653 printf("CGA - Color Graphics Adaptor\n");
657 printf("EGA - Enhanced Graphics Adaptor\n");
661 printf("VGA - Video Graphics Adaptor/Array\n");
662 printf(" VGA Chipset Manufacturer = %s\n",
663 vga_family(screeninfo.vga_family));
664 printf(" VGA Chipset Type = %s\n",
665 vga_type(screeninfo.vga_type));
666 printf(" Support for 132 Column Mode = %s\n",
667 screeninfo.vga_132 ? "Yes" : "No");
671 printf( "Display Monitor Type = ");
673 switch(screeninfo.monitor_type)
676 printf("UNKNOWN Monitor Type\n");
680 printf("Monochrome Monitor\n");
684 printf("Color Monitor\n");
688 printf( "Number of Downloadable Fonts = %d\n",screeninfo.totalfonts);
689 printf( "Number of Virtual Screens = %d\n",screeninfo.totalscreens);
690 printf( "Info Request Screen Number = %d\n",screeninfo.screen_no);
691 printf( "Current Displayed Screen = %d\n",screeninfo.current_screen);
693 if(screeninfo.pure_vt_mode == M_PUREVT)
694 printf( "Terminal Emulation Mode = VT220\n");
696 printf( "Terminal Emulation Mode = VT220 with HP Features\n");
700 switch(screeninfo.screen_size)
727 printf( "UNKNOWN\n");
730 printf( "Force 24 Lines = %s",
731 screeninfo.force_24lines ? "Yes" : "No");
737 findname(unsigned idx)
739 /* try to find a name for palette entry idx */
740 /* if multiple names exist, returns first matching */
743 for(cnp = colnames; cnp->name; cnp++)
748 return (const char *)NULL;
756 for(idx = 0; idx < NVGAPEL; idx++)
760 if(ioctl(fd, VGAREADPEL, &p) < 0)
761 err(2, "ioctl(VGAREADPEL)");
762 palette[idx].r = p.r;
763 palette[idx].g = p.g;
764 palette[idx].b = p.b;
767 /* find last non-empty entry */
768 for(last = NVGAPEL - 1; last; last--)
769 if(palette[last].r || palette[last].g || palette[last].b)
772 if(last != NVGAPEL - 1)
775 /* now, everything's collected. print out table */
776 printf("VGA palette status\n");
777 printf("index red green blue name\n");
778 for(idx = 0; idx < last; idx++)
781 printf("%5d %5d %5d %5d",
782 idx, palette[idx].r, palette[idx].g, palette[idx].b);
783 if(cp = findname(idx))
793 parsepopt(char *arg, unsigned *idx, unsigned *r, unsigned *g, unsigned *b)
798 if(sscanf(arg, "%20[a-zA-Z0-9]%*[,:]%u,%u,%u", firstarg, r, g, b) < 4
799 || strlen(firstarg) == 0)
800 errx(2, "too few args in -p i,r,g,b");
802 if(firstarg[0] >= '0' && firstarg[0] <= '9') {
803 *idx = strtoul(firstarg, NULL, 10);
807 for(i = 0; colnames[i].name; i++)
808 if(strcasecmp(colnames[i].name, firstarg) == 0) {
809 *idx = colnames[i].idx;
812 errx(2, "arg ``%s'' in -p option not recognized", firstarg);