vidcontrol.c revision 75788
12089Ssos/*- 216565Ssos * Copyright (c) 1994-1996 S�ren Schmidt 32089Ssos * All rights reserved. 42089Ssos * 52089Ssos * Redistribution and use in source and binary forms, with or without 62089Ssos * modification, are permitted provided that the following conditions 72089Ssos * are met: 82089Ssos * 1. Redistributions of source code must retain the above copyright 95994Ssos * notice, this list of conditions and the following disclaimer, 105994Ssos * in this position and unchanged. 112089Ssos * 2. Redistributions in binary form must reproduce the above copyright 122089Ssos * notice, this list of conditions and the following disclaimer in the 132089Ssos * documentation and/or other materials provided with the distribution. 142089Ssos * 3. The name of the author may not be used to endorse or promote products 152089Ssos * derived from this software withough specific prior written permission 162089Ssos * 172089Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 182089Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 192089Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 202089Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 212089Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 222089Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232089Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242089Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252089Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 262089Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272089Ssos */ 282089Ssos 2930764Scharnier#ifndef lint 3030764Scharnierstatic const char rcsid[] = 3150479Speter "$FreeBSD: head/usr.sbin/vidcontrol/vidcontrol.c 75788 2001-04-21 13:50:32Z ache $"; 3230764Scharnier#endif /* not lint */ 3330764Scharnier 342089Ssos#include <ctype.h> 3530764Scharnier#include <err.h> 3655849Syokota#include <limits.h> 372089Ssos#include <stdio.h> 3823457Sbrian#include <stdlib.h> 3930764Scharnier#include <string.h> 4023702Speter#include <unistd.h> 4166834Sphk#include <sys/fbio.h> 4266834Sphk#include <sys/consio.h> 432089Ssos#include <sys/errno.h> 4475344Ssobomax#include <sys/types.h> 4575344Ssobomax#include <sys/stat.h> 462089Ssos#include "path.h" 4723457Sbrian#include "decode.h" 482089Ssos 4971642Ssobomax#define _VESA_800x600_DFL_COLS 80 5071642Ssobomax#define _VESA_800x600_DFL_ROWS 25 5171642Ssobomax#define _VESA_800x600_DFL_FNSZ 16 5271642Ssobomax 532089Ssoschar legal_colors[16][16] = { 542089Ssos "black", "blue", "green", "cyan", 552089Ssos "red", "magenta", "brown", "white", 562089Ssos "grey", "lightblue", "lightgreen", "lightcyan", 572089Ssos "lightred", "lightmagenta", "yellow", "lightwhite" 586628Ssos}; 592089Ssosint hex = 0; 606047Ssosint number; 6171642Ssobomaxint vesa_cols = _VESA_800x600_DFL_COLS; 6271642Ssobomaxint vesa_rows = _VESA_800x600_DFL_ROWS; 632089Ssoschar letter; 642089Ssosstruct vid_info info; 652089Ssos 662089Ssos 6730764Scharnierstatic void 686628Ssosusage() 696628Ssos{ 7055849Syokota fprintf(stderr, "%s\n%s\n%s\n%s\n", 7130764Scharnier"usage: vidcontrol [-r fg bg] [-b color] [-c appearance] [-d] [-l scrmap]", 7255849Syokota" [-i adapter | mode] [-L] [-M char] [-m on|off]", 7371642Ssobomax" [-f size file] [-s number] [-t N|off] [-x] [-g geometry]", 7471642Ssobomax" [mode] [fgcol [bgcol]] [show]"); 7530764Scharnier exit(1); 766628Ssos} 776628Ssos 782089Ssoschar * 7975344Ssobomaxnextarg(int ac, char **av, int *indp, int oc, int strict) 802089Ssos{ 812089Ssos if (*indp < ac) 822089Ssos return(av[(*indp)++]); 8375344Ssobomax if (strict != 0) 8475344Ssobomax errx(1, "option requires two arguments -- %c", oc); 8575344Ssobomax return(NULL); 862089Ssos} 872089Ssos 882089Ssoschar * 892089Ssosmkfullname(const char *s1, const char *s2, const char *s3) 902089Ssos{ 916628Ssos static char *buf = NULL; 926628Ssos static int bufl = 0; 936628Ssos int f; 942089Ssos 952089Ssos f = strlen(s1) + strlen(s2) + strlen(s3) + 1; 9652262Sbillf if (f > bufl) { 972089Ssos if (buf) 982089Ssos buf = (char *)realloc(buf, f); 992089Ssos else 1002089Ssos buf = (char *)malloc(f); 10152262Sbillf } 1022089Ssos if (!buf) { 1032089Ssos bufl = 0; 1042089Ssos return(NULL); 1052089Ssos } 1062089Ssos 1072089Ssos bufl = f; 1082089Ssos strcpy(buf, s1); 1092089Ssos strcat(buf, s2); 1102089Ssos strcat(buf, s3); 1112089Ssos return(buf); 1122089Ssos} 1132089Ssos 1142089Ssosvoid 1152089Ssosload_scrnmap(char *filename) 1162089Ssos{ 11723457Sbrian FILE *fd = 0; 1182089Ssos int i, size; 1192089Ssos char *name; 1202089Ssos scrmap_t scrnmap; 1212089Ssos char *prefix[] = {"", "", SCRNMAP_PATH, SCRNMAP_PATH, NULL}; 1222089Ssos char *postfix[] = {"", ".scm", "", ".scm"}; 1232089Ssos 1242089Ssos for (i=0; prefix[i]; i++) { 1252089Ssos name = mkfullname(prefix[i], filename, postfix[i]); 12623457Sbrian fd = fopen(name, "r"); 12723457Sbrian if (fd) 1282089Ssos break; 1292089Ssos } 1302089Ssos if (fd == NULL) { 13130764Scharnier warn("screenmap file not found"); 1322089Ssos return; 1332089Ssos } 1342089Ssos size = sizeof(scrnmap); 13575344Ssobomax if (decode(fd, (char *)&scrnmap, size) != size) { 1362089Ssos rewind(fd); 1372089Ssos if (fread(&scrnmap, 1, size, fd) != size) { 13830764Scharnier warnx("bad screenmap file"); 13923457Sbrian fclose(fd); 1402089Ssos return; 1412089Ssos } 1422089Ssos } 1432089Ssos if (ioctl(0, PIO_SCRNMAP, &scrnmap) < 0) 14430764Scharnier warn("can't load screenmap"); 14523457Sbrian fclose(fd); 1462089Ssos} 1472089Ssos 1482089Ssosvoid 1492089Ssosload_default_scrnmap() 1502089Ssos{ 1516628Ssos scrmap_t scrnmap; 1522089Ssos int i; 1532089Ssos 1542089Ssos for (i=0; i<256; i++) 1552089Ssos *((char*)&scrnmap + i) = i; 1562089Ssos if (ioctl(0, PIO_SCRNMAP, &scrnmap) < 0) 15730764Scharnier warn("can't load default screenmap"); 1582089Ssos} 1592089Ssos 1602089Ssosvoid 1612089Ssosprint_scrnmap() 1622089Ssos{ 1632089Ssos unsigned char map[256]; 1642089Ssos int i; 1652089Ssos 1662089Ssos if (ioctl(0, GIO_SCRNMAP, &map) < 0) { 16730764Scharnier warn("getting screenmap"); 1682089Ssos return; 1692089Ssos } 1702089Ssos for (i=0; i<sizeof(map); i++) { 1712089Ssos if (i > 0 && i % 16 == 0) 1722089Ssos fprintf(stdout, "\n"); 1732089Ssos if (hex) 1748857Srgrimes fprintf(stdout, " %02x", map[i]); 1752089Ssos else 1762089Ssos fprintf(stdout, " %03d", map[i]); 1772089Ssos } 1782089Ssos fprintf(stdout, "\n"); 1792089Ssos 1802089Ssos} 1812089Ssos 18275344Ssobomaxint 18375344Ssobomaxfsize(FILE *file) 18475344Ssobomax{ 18575344Ssobomax struct stat sb; 18675344Ssobomax 18775344Ssobomax if (fstat(fileno(file), &sb) == 0) 18875344Ssobomax return sb.st_size; 18975344Ssobomax else 19075344Ssobomax return -1; 19175344Ssobomax} 19275344Ssobomax 19375344Ssobomax#define DATASIZE(x) ((x).w * (x).h * 256 / 8) 19475344Ssobomax 1958857Srgrimesvoid 1962089Ssosload_font(char *type, char *filename) 1972089Ssos{ 19875344Ssobomax FILE *fd = NULL; 19975344Ssobomax int h, i, size, w; 20075344Ssobomax unsigned long io = 0; /* silence stupid gcc(1) in the Wall mode */ 2012089Ssos char *name, *fontmap; 2022089Ssos char *prefix[] = {"", "", FONT_PATH, FONT_PATH, NULL}; 2032089Ssos char *postfix[] = {"", ".fnt", "", ".fnt"}; 2042089Ssos 20575344Ssobomax struct sizeinfo { 20675344Ssobomax int w; 20775344Ssobomax int h; 20875344Ssobomax unsigned long io; 20975344Ssobomax } sizes[] = {{8, 16, PIO_FONT8x16}, 21075344Ssobomax {8, 14, PIO_FONT8x14}, 21175344Ssobomax {8, 8, PIO_FONT8x8}, 21275344Ssobomax {0, 0, 0}}; 21375344Ssobomax 2142089Ssos for (i=0; prefix[i]; i++) { 2152089Ssos name = mkfullname(prefix[i], filename, postfix[i]); 21623457Sbrian fd = fopen(name, "r"); 21723457Sbrian if (fd) 2182089Ssos break; 2192089Ssos } 2202089Ssos if (fd == NULL) { 22175344Ssobomax warn("%s: can't load font file", filename); 2222089Ssos return; 2232089Ssos } 22475344Ssobomax if (type != NULL) { 22575344Ssobomax size = 0; 22675344Ssobomax if (sscanf(type, "%dx%d", &w, &h) == 2) 22775344Ssobomax for (i = 0; sizes[i].w != 0; i++) 22875344Ssobomax if (sizes[i].w == w && sizes[i].h == h) { 22975344Ssobomax size = DATASIZE(sizes[i]); 23075344Ssobomax io = sizes[i].io; 23175344Ssobomax } 23275344Ssobomax 23375344Ssobomax if (size == 0) { 23475344Ssobomax warnx("%s: bad font size specification", type); 23575344Ssobomax fclose(fd); 23675344Ssobomax return; 23775344Ssobomax } 23875344Ssobomax } else { 23975344Ssobomax /* Apply heuristics */ 24075344Ssobomax int j; 24175344Ssobomax int dsize[2]; 24275344Ssobomax 24375344Ssobomax size = DATASIZE(sizes[0]); 24475344Ssobomax fontmap = (char*) malloc(size); 24575344Ssobomax dsize[0] = decode(fd, fontmap, size); 24675344Ssobomax dsize[1] = fsize(fd); 24775344Ssobomax free(fontmap); 24875344Ssobomax 24975344Ssobomax size = 0; 25075344Ssobomax for (j = 0; j < 2; j++) 25175344Ssobomax for (i = 0; sizes[i].w != 0; i++) 25275344Ssobomax if (DATASIZE(sizes[i]) == dsize[j]) { 25375344Ssobomax size = dsize[j]; 25475344Ssobomax io = sizes[i].io; 25575344Ssobomax j = 2; /* XXX */ 25675344Ssobomax break; 25775344Ssobomax } 25875344Ssobomax 25975344Ssobomax if (size == 0) { 26075344Ssobomax warnx("%s: can't guess font size", filename); 26175344Ssobomax fclose(fd); 26275344Ssobomax return; 26375344Ssobomax } 26475344Ssobomax rewind(fd); 2652089Ssos } 26675344Ssobomax 2672089Ssos fontmap = (char*) malloc(size); 26875344Ssobomax if (decode(fd, fontmap, size) != size) { 2692089Ssos rewind(fd); 27075344Ssobomax if (fsize(fd) != size || fread(fontmap, 1, size, fd) != size) { 27175344Ssobomax warnx("%s: bad font file", filename); 27223457Sbrian fclose(fd); 2732089Ssos free(fontmap); 2742089Ssos return; 2752089Ssos } 2762089Ssos } 2772089Ssos if (ioctl(0, io, fontmap) < 0) 27830764Scharnier warn("can't load font"); 27923457Sbrian fclose(fd); 2802089Ssos free(fontmap); 2812089Ssos} 2822089Ssos 2832089Ssosvoid 2842089Ssosset_screensaver_timeout(char *arg) 2852089Ssos{ 2862089Ssos int nsec; 2872089Ssos 2882089Ssos if (!strcmp(arg, "off")) 2892089Ssos nsec = 0; 2902089Ssos else { 2912089Ssos nsec = atoi(arg); 2922089Ssos if ((*arg == '\0') || (nsec < 1)) { 29330764Scharnier warnx("argument must be a positive number"); 2942089Ssos return; 2952089Ssos } 2962089Ssos } 2972089Ssos if (ioctl(0, CONS_BLANKTIME, &nsec) == -1) 29830764Scharnier warn("setting screensaver period"); 2992089Ssos} 3002089Ssos 3012089Ssosvoid 3025536Ssosset_cursor_type(char *appearence) 3032089Ssos{ 3045536Ssos int type; 3052089Ssos 3066230Ssos if (!strcmp(appearence, "normal")) 3076230Ssos type = 0; 3086230Ssos else if (!strcmp(appearence, "blink")) 3095536Ssos type = 1; 3106230Ssos else if (!strcmp(appearence, "destructive")) 3116230Ssos type = 3; 3125536Ssos else { 31330764Scharnier warnx("argument to -c must be normal, blink or destructive"); 3142089Ssos return; 3152089Ssos } 3165536Ssos ioctl(0, CONS_CURSORTYPE, &type); 3172089Ssos} 3182089Ssos 31923457Sbrianvoid 3202089Ssosvideo_mode(int argc, char **argv, int *index) 3212089Ssos{ 32239592Syokota static struct { 32339592Syokota char *name; 32439592Syokota unsigned long mode; 32539592Syokota } modes[] = { 32639592Syokota { "80x25", SW_TEXT_80x25 }, 32739592Syokota { "80x30", SW_TEXT_80x30 }, 32839592Syokota { "80x43", SW_TEXT_80x43 }, 32939592Syokota { "80x50", SW_TEXT_80x50 }, 33039592Syokota { "80x60", SW_TEXT_80x60 }, 33139592Syokota { "132x25", SW_TEXT_132x25 }, 33239592Syokota { "132x30", SW_TEXT_132x30 }, 33339592Syokota { "132x43", SW_TEXT_132x43 }, 33439592Syokota { "132x50", SW_TEXT_132x50 }, 33539592Syokota { "132x60", SW_TEXT_132x60 }, 33639592Syokota { "VGA_40x25", SW_VGA_C40x25 }, 33739592Syokota { "VGA_80x25", SW_VGA_C80x25 }, 33839592Syokota { "VGA_80x30", SW_VGA_C80x30 }, 33939592Syokota { "VGA_80x50", SW_VGA_C80x50 }, 34039592Syokota { "VGA_80x60", SW_VGA_C80x60 }, 34148105Syokota#ifdef SW_VGA_C90x25 34248105Syokota { "VGA_90x25", SW_VGA_C90x25 }, 34348105Syokota { "VGA_90x30", SW_VGA_C90x30 }, 34448105Syokota { "VGA_90x43", SW_VGA_C90x43 }, 34548105Syokota { "VGA_90x50", SW_VGA_C90x50 }, 34648105Syokota { "VGA_90x60", SW_VGA_C90x60 }, 34748105Syokota#endif 34839592Syokota { "VGA_320x200", SW_VGA_CG320 }, 34939592Syokota { "EGA_80x25", SW_ENH_C80x25 }, 35039592Syokota { "EGA_80x43", SW_ENH_C80x43 }, 35139592Syokota { "VESA_132x25", SW_VESA_C132x25 }, 35239592Syokota { "VESA_132x43", SW_VESA_C132x43 }, 35339592Syokota { "VESA_132x50", SW_VESA_C132x50 }, 35439592Syokota { "VESA_132x60", SW_VESA_C132x60 }, 35539592Syokota { "VESA_800x600", SW_VESA_800x600 }, 35639592Syokota { NULL }, 35739592Syokota }; 35842605Smjacob unsigned long mode = 0; 35948105Syokota int cur_mode; 36048105Syokota int ioerr; 36139287Ssos int size[3]; 36239592Syokota int i; 3632089Ssos 36448105Syokota if (ioctl(0, CONS_GET, &cur_mode) < 0) 36548105Syokota err(1, "cannot get the current video mode"); 3662089Ssos if (*index < argc) { 36739592Syokota for (i = 0; modes[i].name != NULL; ++i) { 36839592Syokota if (!strcmp(argv[*index], modes[i].name)) { 36939592Syokota mode = modes[i].mode; 37039592Syokota break; 37139592Syokota } 37239592Syokota } 37339592Syokota if (modes[i].name == NULL) 3742089Ssos return; 3752089Ssos if (ioctl(0, mode, NULL) < 0) 37630764Scharnier warn("cannot set videomode"); 37739287Ssos if (mode == SW_VESA_800x600) { 37871642Ssobomax /* columns */ 37971642Ssobomax if ((vesa_cols * 8 > 800) || (vesa_cols <= 0)) { 38071642Ssobomax warnx("incorrect number of columns: %d", 38171642Ssobomax vesa_cols); 38271642Ssobomax size[0] = _VESA_800x600_DFL_COLS; 38371642Ssobomax } else { 38471642Ssobomax size[0] = vesa_cols; 38571642Ssobomax } 38671642Ssobomax /* rows */ 38771642Ssobomax if ((vesa_rows * _VESA_800x600_DFL_FNSZ > 600) || 38871642Ssobomax (vesa_rows <=0)) { 38971642Ssobomax warnx("incorrect number of rows: %d", 39071642Ssobomax vesa_rows); 39171642Ssobomax size[1] = _VESA_800x600_DFL_ROWS; 39271642Ssobomax } else { 39371642Ssobomax size[1] = vesa_rows; 39471642Ssobomax } 39571642Ssobomax /* font size */ 39671642Ssobomax size[2] = _VESA_800x600_DFL_FNSZ; 39748105Syokota if (ioctl(0, KDRASTER, size)) { 39848105Syokota ioerr = errno; 39948105Syokota if (cur_mode >= M_VESA_BASE) 40048105Syokota ioctl(0, _IO('V', cur_mode), NULL); 40148105Syokota else 40248105Syokota ioctl(0, _IO('S', cur_mode), NULL); 40348105Syokota warnc(ioerr, "cannot activate raster display"); 40448105Syokota } 40539287Ssos } 4062089Ssos (*index)++; 4072089Ssos } 4082089Ssos return; 4092089Ssos} 4108857Srgrimes 4112089Ssosint 4122089Ssosget_color_number(char *color) 4132089Ssos{ 4142089Ssos int i; 4152089Ssos 4162089Ssos for (i=0; i<16; i++) 4172089Ssos if (!strcmp(color, legal_colors[i])) 4182089Ssos return i; 4192089Ssos return -1; 4202089Ssos} 4212089Ssos 42223457Sbrianvoid 4232089Ssosset_normal_colors(int argc, char **argv, int *index) 4242089Ssos{ 4252089Ssos int color; 4262089Ssos 4272089Ssos if (*index < argc && (color = get_color_number(argv[*index])) != -1) { 4282089Ssos (*index)++; 4292089Ssos fprintf(stderr, "[=%dF", color); 4308857Srgrimes if (*index < argc 4318857Srgrimes && (color = get_color_number(argv[*index])) != -1 4322089Ssos && color < 8) { 4332089Ssos (*index)++; 4342089Ssos fprintf(stderr, "[=%dG", color); 4352089Ssos } 4362089Ssos } 4372089Ssos} 4382089Ssos 43923457Sbrianvoid 4402089Ssosset_reverse_colors(int argc, char **argv, int *index) 4412089Ssos{ 4422089Ssos int color; 4432089Ssos 4442089Ssos if ((color = get_color_number(argv[*(index)-1])) != -1) { 4452089Ssos fprintf(stderr, "[=%dH", color); 4468857Srgrimes if (*index < argc 4478857Srgrimes && (color = get_color_number(argv[*index])) != -1 4482089Ssos && color < 8) { 4492089Ssos (*index)++; 4502089Ssos fprintf(stderr, "[=%dI", color); 4512089Ssos } 4522089Ssos } 4532089Ssos} 4542089Ssos 45523457Sbrianvoid 45623457Sbrianset_console(char *arg) 45723457Sbrian{ 45823457Sbrian int n; 45923457Sbrian 46023457Sbrian if( !arg || strspn(arg,"0123456789") != strlen(arg)) { 46130764Scharnier warnx("bad console number"); 46223457Sbrian return; 46323457Sbrian } 46423457Sbrian 46523457Sbrian n = atoi(arg); 46651393Syokota if (n < 1 || n > 16) { 46730764Scharnier warnx("console number out of range"); 46842605Smjacob } else if (ioctl(0, VT_ACTIVATE, (caddr_t) (long) n) == -1) 46930764Scharnier warn("ioctl(VT_ACTIVATE)"); 47023457Sbrian} 47123457Sbrian 47223457Sbrianvoid 4732089Ssosset_border_color(char *arg) 4742089Ssos{ 4752089Ssos int color; 4762089Ssos 4772089Ssos if ((color = get_color_number(arg)) != -1) { 4782089Ssos fprintf(stderr, "[=%dA", color); 4792089Ssos } 4802089Ssos else 4818857Srgrimes usage(); 4822089Ssos} 4832089Ssos 48416565Ssosvoid 48555849Syokotaset_mouse_char(char *arg) 48655849Syokota{ 48755849Syokota struct mouse_info mouse; 48855849Syokota long l; 48955849Syokota 49055849Syokota l = strtol(arg, NULL, 0); 49175788Sache if ((l < 0) || (l > UCHAR_MAX - 3)) { 49275788Sache warnx("argument to -M must be 0 through %d", UCHAR_MAX - 3); 49355849Syokota return; 49455849Syokota } 49555849Syokota mouse.operation = MOUSE_MOUSECHAR; 49655849Syokota mouse.u.mouse_char = (int)l; 49755849Syokota ioctl(0, CONS_MOUSECTL, &mouse); 49855849Syokota} 49955849Syokota 50055849Syokotavoid 50116565Ssosset_mouse(char *arg) 50216565Ssos{ 50316565Ssos struct mouse_info mouse; 50416565Ssos 50516565Ssos if (!strcmp(arg, "on")) 50616565Ssos mouse.operation = MOUSE_SHOW; 50716565Ssos else if (!strcmp(arg, "off")) 50816565Ssos mouse.operation = MOUSE_HIDE; 50916565Ssos else { 51030764Scharnier warnx("argument to -m must either on or off"); 51116565Ssos return; 51216565Ssos } 51316565Ssos ioctl(0, CONS_MOUSECTL, &mouse); 51416565Ssos} 51516565Ssos 51639287Ssosstatic char 51739287Ssos*adapter_name(int type) 51839287Ssos{ 51939287Ssos static struct { 52039287Ssos int type; 52139287Ssos char *name; 52239287Ssos } names[] = { 52339287Ssos { KD_MONO, "MDA" }, 52439287Ssos { KD_HERCULES, "Hercules" }, 52539287Ssos { KD_CGA, "CGA" }, 52639287Ssos { KD_EGA, "EGA" }, 52739287Ssos { KD_VGA, "VGA" }, 52839287Ssos { KD_PC98, "PC-98xx" }, 52948105Syokota { KD_TGA, "TGA" }, 53039287Ssos { -1, "Unknown" }, 53139287Ssos }; 53239287Ssos int i; 53339287Ssos 53439287Ssos for (i = 0; names[i].type != -1; ++i) 53539287Ssos if (names[i].type == type) 53639287Ssos break; 53739287Ssos return names[i].name; 53839287Ssos} 53939287Ssos 54023457Sbrianvoid 54139287Ssosshow_adapter_info(void) 54239287Ssos{ 54342505Syokota struct video_adapter_info ad; 54439287Ssos 54539287Ssos ad.va_index = 0; 54639287Ssos if (ioctl(0, CONS_ADPINFO, &ad)) { 54739287Ssos warn("failed to obtain adapter information"); 54839287Ssos return; 54939287Ssos } 55039287Ssos 55142505Syokota printf("fb%d:\n", ad.va_index); 55242505Syokota printf(" %.*s%d, type:%s%s (%d), flags:0x%x\n", 55342505Syokota (int)sizeof(ad.va_name), ad.va_name, ad.va_unit, 55439287Ssos (ad.va_flags & V_ADP_VESA) ? "VESA " : "", 55542505Syokota adapter_name(ad.va_type), ad.va_type, ad.va_flags); 55639287Ssos printf(" initial mode:%d, current mode:%d, BIOS mode:%d\n", 55739287Ssos ad.va_initial_mode, ad.va_mode, ad.va_initial_bios_mode); 55848105Syokota printf(" frame buffer window:0x%x, buffer size:0x%x\n", 55948105Syokota ad.va_window, ad.va_buffer_size); 56048105Syokota printf(" window size:0x%x, origin:0x%x\n", 56148105Syokota ad.va_window_size, ad.va_window_orig); 56248105Syokota printf(" display start address (%d, %d), scan line width:%d\n", 56348105Syokota ad.va_disp_start.x, ad.va_disp_start.y, ad.va_line_width); 56448105Syokota printf(" reserved:0x%x\n", ad.va_unused0); 56539287Ssos} 56639287Ssos 56739287Ssosvoid 56839287Ssosshow_mode_info(void) 56939287Ssos{ 57039287Ssos struct video_info info; 57139287Ssos char buf[80]; 57239287Ssos int mode; 57339287Ssos int c; 57439287Ssos 57539287Ssos printf(" mode# flags type size " 57639287Ssos "font window linear buffer\n"); 57739287Ssos printf("---------------------------------------" 57839287Ssos "---------------------------------------\n"); 57939287Ssos for (mode = 0; mode < M_VESA_MODE_MAX; ++mode) { 58039287Ssos info.vi_mode = mode; 58139287Ssos if (ioctl(0, CONS_MODEINFO, &info)) 58239287Ssos continue; 58348105Syokota if (info.vi_mode != mode) 58448105Syokota continue; 58539287Ssos 58639287Ssos printf("%3d (0x%03x)", mode, mode); 58739287Ssos printf(" 0x%08x", info.vi_flags); 58839287Ssos if (info.vi_flags & V_INFO_GRAPHICS) { 58939287Ssos c = 'G'; 59039287Ssos snprintf(buf, sizeof(buf), "%dx%dx%d %d", 59139287Ssos info.vi_width, info.vi_height, 59239287Ssos info.vi_depth, info.vi_planes); 59339287Ssos } else { 59439287Ssos c = 'T'; 59539287Ssos snprintf(buf, sizeof(buf), "%dx%d", 59639287Ssos info.vi_width, info.vi_height); 59739287Ssos } 59839287Ssos printf(" %c %-15s", c, buf); 59939287Ssos snprintf(buf, sizeof(buf), "%dx%d", 60039287Ssos info.vi_cwidth, info.vi_cheight); 60139287Ssos printf(" %-5s", buf); 60239287Ssos printf(" 0x%05x %2dk %2dk", 60343186Sdfr info.vi_window, (int)info.vi_window_size/1024, 60443186Sdfr (int)info.vi_window_gran/1024); 60548105Syokota printf(" 0x%08x %dk\n", 60643186Sdfr info.vi_buffer, (int)info.vi_buffer_size/1024); 60739287Ssos } 60839287Ssos} 60939287Ssos 61039287Ssosvoid 61139287Ssosshow_info(char *arg) 61239287Ssos{ 61339287Ssos if (!strcmp(arg, "adapter")) 61439287Ssos show_adapter_info(); 61539287Ssos else if (!strcmp(arg, "mode")) 61639287Ssos show_mode_info(); 61739287Ssos else { 61839287Ssos warnx("argument to -i must either adapter or mode"); 61939287Ssos return; 62039287Ssos } 62139287Ssos} 62239287Ssos 62339287Ssosvoid 6242089Ssostest_frame() 6252089Ssos{ 6262089Ssos int i; 6272089Ssos 6282089Ssos fprintf(stdout, "[=0G\n\n"); 6292089Ssos for (i=0; i<8; i++) { 6302089Ssos fprintf(stdout, "[=15F[=0G %2d [=%dF%-16s" 6312089Ssos "[=15F[=0G %2d [=%dF%-16s " 6322089Ssos "[=15F %2d [=%dGBACKGROUND[=0G\n", 6338857Srgrimes i, i, legal_colors[i], i+8, i+8, 6348857Srgrimes legal_colors[i+8], i, i); 6352089Ssos } 6362089Ssos fprintf(stdout, "[=%dF[=%dG[=%dH[=%dI\n", 6378857Srgrimes info.mv_norm.fore, info.mv_norm.back, 6382089Ssos info.mv_rev.fore, info.mv_rev.back); 6392089Ssos} 6402089Ssos 64123457Sbrianint 6422089Ssosmain(int argc, char **argv) 6432089Ssos{ 64475344Ssobomax char *font, *type; 64575344Ssobomax int opt; 6462089Ssos 6478857Srgrimes 6482089Ssos info.size = sizeof(info); 64930764Scharnier if (ioctl(0, CONS_GETINFO, &info) < 0) 65030764Scharnier err(1, "must be on a virtual console"); 65171642Ssobomax while((opt = getopt(argc, argv, "b:c:df:g:i:l:LM:m:r:s:t:x")) != -1) 6522089Ssos switch(opt) { 65316565Ssos case 'b': 65416565Ssos set_border_color(optarg); 65516565Ssos break; 6562089Ssos case 'c': 6575536Ssos set_cursor_type(optarg); 6582089Ssos break; 6592089Ssos case 'd': 6602089Ssos print_scrnmap(); 6612089Ssos break; 6622089Ssos case 'f': 66375344Ssobomax type = optarg; 66475344Ssobomax font = nextarg(argc, argv, &optind, 'f', 0); 66575344Ssobomax if (font == NULL) { 66675344Ssobomax type = NULL; 66775344Ssobomax font = optarg; 66875344Ssobomax } 66975344Ssobomax load_font(type, font); 6702089Ssos break; 67171642Ssobomax case 'g': 67271642Ssobomax if (sscanf(optarg, "%dx%d", &vesa_cols, 67371642Ssobomax &vesa_rows) != 2) { 67471642Ssobomax warnx("incorrect geometry: %s", optarg); 67571642Ssobomax usage(); 67671642Ssobomax } 67771642Ssobomax break; 67839287Ssos case 'i': 67939287Ssos show_info(optarg); 68039287Ssos break; 6812089Ssos case 'l': 6822089Ssos load_scrnmap(optarg); 6832089Ssos break; 6842089Ssos case 'L': 6852089Ssos load_default_scrnmap(); 6862089Ssos break; 68755849Syokota case 'M': 68855849Syokota set_mouse_char(optarg); 68955849Syokota break; 69016565Ssos case 'm': 69116565Ssos set_mouse(optarg); 69216565Ssos break; 6932089Ssos case 'r': 6942089Ssos set_reverse_colors(argc, argv, &optind); 6952089Ssos break; 69623457Sbrian case 's': 69723457Sbrian set_console(optarg); 69823457Sbrian break; 6992089Ssos case 't': 7002089Ssos set_screensaver_timeout(optarg); 7012089Ssos break; 7022089Ssos case 'x': 7032089Ssos hex = 1; 7042089Ssos break; 7052089Ssos default: 7062089Ssos usage(); 7072089Ssos } 70823457Sbrian video_mode(argc, argv, &optind); 70923457Sbrian set_normal_colors(argc, argv, &optind); 7102089Ssos if (optind < argc && !strcmp(argv[optind], "show")) { 7112089Ssos test_frame(); 7122089Ssos optind++; 7132089Ssos } 71430764Scharnier if ((optind != argc) || (argc == 1)) 7152089Ssos usage(); 71623457Sbrian return 0; 7172089Ssos} 7182089Ssos 719