1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
|
/*
* Linux Frame Buffer Device Configuration
*
* Copyright 1995-1999 by Geert Uytterhoeven
* (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*
* --------------------------------------------------------------------------
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux
* distribution for more details.
*
* Petr Vandrovec <vandrove@vc.cvut.cz>:
* -grayscale, -rgba, -nonstd, VGA modes reporting
*
* Brad Midgley <brad@exodus.pht.com>:
* -match
*
*/
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <sys/stat.h>
struct file;
struct inode;
#include "fb.h"
#include "fbset.h"
/*
* Default Frame Buffer Special Device Node
*/
#define DEFAULT_FRAMEBUFFER "/dev/fb0"
/*
* Default Video Mode Database File
*/
#define DEFAULT_MODEDBFILE "/etc/fb.modes"
/*
* Command Line Options
*/
static const char *ProgramName;
static int Opt_test = 0;
static int Opt_show = 0;
static int Opt_info = 0;
static int Opt_version = 0;
static int Opt_verbose = 0;
static int Opt_xfree86 = 0;
static int Opt_change = 0;
static int Opt_all = 0;
static const char *Opt_fb = NULL;
const char *Opt_modedb = DEFAULT_MODEDBFILE;
static const char *Opt_xres = NULL;
static const char *Opt_yres = NULL;
static const char *Opt_vxres = NULL;
static const char *Opt_vyres = NULL;
static const char *Opt_depth = NULL;
static const char *Opt_pixclock = NULL;
static const char *Opt_left = NULL;
static const char *Opt_right = NULL;
static const char *Opt_upper = NULL;
static const char *Opt_lower = NULL;
static const char *Opt_hslen = NULL;
static const char *Opt_vslen = NULL;
static const char *Opt_accel = NULL;
static const char *Opt_hsync = NULL;
static const char *Opt_vsync = NULL;
static const char *Opt_csync = NULL;
static const char *Opt_gsync = NULL;
static const char *Opt_extsync = NULL;
static const char *Opt_bcast = NULL;
static const char *Opt_laced = NULL;
static const char *Opt_double = NULL;
static const char *Opt_move = NULL;
static const char *Opt_step = NULL;
static const char *Opt_modename = NULL;
static const char *Opt_rgba = NULL;
static const char *Opt_nonstd = NULL;
static const char *Opt_grayscale = NULL;
static const char *Opt_matchyres = NULL;
static struct {
const char *name;
const char **value;
const int change;
} Options[] = {
{ "-fb", &Opt_fb, 0 },
{ "-db", &Opt_modedb, 0 },
{ "-xres", &Opt_xres, 1 },
{ "-yres", &Opt_yres, 1 },
{ "-vxres", &Opt_vxres, 1 },
{ "-vyres", &Opt_vyres, 1 },
{ "-depth", &Opt_depth, 1 },
{ "-nonstd", &Opt_nonstd, 1},
{ "-pixclock", &Opt_pixclock, 1 },
{ "-left", &Opt_left, 1 },
{ "-right", &Opt_right, 1 },
{ "-upper", &Opt_upper, 1 },
{ "-lower", &Opt_lower, 1 },
{ "-hslen", &Opt_hslen, 1 },
{ "-vslen", &Opt_vslen, 1 },
{ "-accel", &Opt_accel, 1 },
{ "-hsync", &Opt_hsync, 1 },
{ "-vsync", &Opt_vsync, 1 },
{ "-csync", &Opt_csync, 1 },
{ "-gsync", &Opt_gsync, 1 },
{ "-extsync", &Opt_extsync, 1 },
{ "-bcast", &Opt_bcast, 1 },
{ "-laced", &Opt_laced, 1 },
{ "-double", &Opt_double, 1 },
{ "-move", &Opt_move, 1 },
{ "-step", &Opt_step, 1 },
{ "-rgba", &Opt_rgba, 1 },
{ "-grayscale", &Opt_grayscale, 1 },
{ NULL, NULL, 0 }
};
/*
* Video Mode Database
*/
struct VideoMode *VideoModes = NULL;
/*
* Hardware Text Modes
*/
static struct textentry {
__u32 id;
const char *name;
} Textmodes[] = {
{ FB_AUX_TEXT_MDA, "Monochrome text" },
{ FB_AUX_TEXT_CGA, "CGA/EGA/VGA Color text" },
{ FB_AUX_TEXT_S3_MMIO, "S3 MMIO fasttext" },
{ FB_AUX_TEXT_MGA_STEP16, "MGA Millennium I step 16 text" },
{ FB_AUX_TEXT_MGA_STEP8, "MGA step 8 text" },
};
static struct textentry VGAModes[] = {
{ FB_AUX_VGA_PLANES_VGA4, "VGA 16 colors in 4 planes" },
{ FB_AUX_VGA_PLANES_CFB4, "VGA 16 colors in 1 plane" },
{ FB_AUX_VGA_PLANES_CFB8, "VGA 256 colors in 4 planes" },
/* last entry has name == NULL */
{ 0, NULL}
};
/*
* Hardware Accelerators
*/
static struct accelentry {
__u32 id;
const char *name;
} Accelerators[] = {
{ FB_ACCEL_NONE, "No" },
{ FB_ACCEL_ATARIBLITT, "Atari Blitter" },
{ FB_ACCEL_AMIGABLITT, "Amiga Blitter" },
{ FB_ACCEL_S3_TRIO64, "S3 Trio64" },
{ FB_ACCEL_NCR_77C32BLT, "NCR 77C32BLT" },
{ FB_ACCEL_S3_VIRGE, "S3 ViRGE" },
{ FB_ACCEL_ATI_MACH64GX, "ATI Mach64GX" },
{ FB_ACCEL_DEC_TGA, "DEC 21030 TGA" },
{ FB_ACCEL_ATI_MACH64CT, "ATI Mach64CT" },
{ FB_ACCEL_ATI_MACH64VT, "ATI Mach64VT" },
{ FB_ACCEL_ATI_MACH64GT, "ATI Mach64GT" },
{ FB_ACCEL_SUN_CREATOR, "Sun Creator/Creator3D" },
{ FB_ACCEL_SUN_CGSIX, "Sun cg6" },
{ FB_ACCEL_SUN_LEO, "Sun leo/zx" },
{ FB_ACCEL_IMS_TWINTURBO, "IMS Twin Turbo" },
{ FB_ACCEL_3DLABS_PERMEDIA2, "3Dlabs Permedia 2" },
{ FB_ACCEL_MATROX_MGA2064W, "Matrox MGA2064W (Millennium)" },
{ FB_ACCEL_MATROX_MGA1064SG, "Matrox MGA1064SG (Mystique)" },
{ FB_ACCEL_MATROX_MGA2164W, "Matrox MGA2164W (Millennium II)" },
{ FB_ACCEL_MATROX_MGA2164W_AGP, "Matrox MGA2164W (Millennium II AGP)" },
{ FB_ACCEL_MATROX_MGAG100, "Matrox G100 (Productiva G100)" },
{ FB_ACCEL_MATROX_MGAG200, "Matrox G200 (Millennium, Mystique)" },
{ FB_ACCEL_SUN_CG14, "Sun cg14" },
{ FB_ACCEL_SUN_BWTWO, "Sun bw2" },
{ FB_ACCEL_SUN_CGTHREE, "Sun cg3" },
{ FB_ACCEL_SUN_TCX, "Sun tcx" },
{ FB_ACCEL_MATROX_MGAG400, "Matrox G400" },
};
/*
* Current Video Mode
*/
struct VideoMode Current;
/*
* Function Prototypes
*/
int OpenFrameBuffer(const char *name);
void CloseFrameBuffer(int fh);
void GetVarScreenInfo(int fh, struct fb_var_screeninfo *var);
void SetVarScreenInfo(int fh, struct fb_var_screeninfo *var);
void GetFixScreenInfo(int fh, struct fb_fix_screeninfo *fix);
static void ConvertFromVideoMode(const struct VideoMode *vmode,
struct fb_var_screeninfo *var);
static void ConvertToVideoMode(const struct fb_var_screeninfo *var,
struct VideoMode *vmode);
static int atoboolean(const char *var);
static void ReadModeDB(void);
static struct VideoMode *FindVideoMode(const char *name);
static void ModifyVideoMode(struct VideoMode *vmode);
static void DisplayVModeInfo(struct VideoMode *vmode);
static void DisplayFBInfo(struct fb_fix_screeninfo *fix);
static int FillScanRates(struct VideoMode *vmode);
static void Usage(void) __attribute__ ((noreturn));
int main(int argc, char *argv[]);
/*
* Print an Error Message and Exit
*/
void Die(const char *fmt, ...)
{
va_list ap;
fflush(stdout);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
exit(1);
}
/*
* Open the Frame Buffer Device
*/
int OpenFrameBuffer(const char *name)
{
int fh;
if (Opt_verbose)
printf("Opening frame buffer device `%s'\n", name);
if ((fh = open(name, O_RDONLY)) == -1)
Die("open %s: %s\n", name, strerror(errno));
return fh;
}
/*
* Close the Frame Buffer Device
*/
void CloseFrameBuffer(int fh)
{
close(fh);
}
/*
* Get the Variable Part of the Screen Info
*/
void GetVarScreenInfo(int fh, struct fb_var_screeninfo *var)
{
if (ioctl(fh, FBIOGET_VSCREENINFO, var))
Die("ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
}
/*
* Set (and Get) the Variable Part of the Screen Info
*/
void SetVarScreenInfo(int fh, struct fb_var_screeninfo *var)
{
if (ioctl(fh, FBIOPUT_VSCREENINFO, var))
Die("ioctl FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
}
/*
* Get the Fixed Part of the Screen Info
*/
void GetFixScreenInfo(int fh, struct fb_fix_screeninfo *fix)
{
if (ioctl(fh, FBIOGET_FSCREENINFO, fix))
Die("ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno));
}
/*
* Conversion Routines
*/
static void ConvertFromVideoMode(const struct VideoMode *vmode,
struct fb_var_screeninfo *var)
{
memset(var, 0, sizeof(struct fb_var_screeninfo));
var->xres = vmode->xres;
var->yres = vmode->yres;
var->xres_virtual = vmode->vxres;
var->yres_virtual = vmode->vyres;
var->bits_per_pixel = vmode->depth;
var->nonstd = vmode->nonstd;
if (Opt_test)
var->activate = FB_ACTIVATE_TEST;
else
var->activate = FB_ACTIVATE_NOW;
if (Opt_all)
var->activate = FB_ACTIVATE_ALL;
var->accel_flags = vmode->accel_flags;
var->pixclock = vmode->pixclock;
var->left_margin = vmode->left;
var->right_margin = vmode->right;
var->upper_margin = vmode->upper;
var->lower_margin = vmode->lower;
var->hsync_len = vmode->hslen;
var->vsync_len = vmode->vslen;
if (vmode->hsync == HIGH)
var->sync |= FB_SYNC_HOR_HIGH_ACT;
if (vmode->vsync == HIGH)
var->sync |= FB_SYNC_VERT_HIGH_ACT;
if (vmode->csync == HIGH)
var->sync |= FB_SYNC_COMP_HIGH_ACT;
if (vmode->gsync == HIGH)
var->sync |= FB_SYNC_ON_GREEN;
if (vmode->extsync == TRUE)
var->sync |= FB_SYNC_EXT;
if (vmode->bcast == TRUE)
var->sync |= FB_SYNC_BROADCAST;
if (vmode->laced == TRUE)
var->vmode = FB_VMODE_INTERLACED;
else if (vmode->dblscan == TRUE)
var->vmode = FB_VMODE_DOUBLE;
else
var->vmode = FB_VMODE_NONINTERLACED;
var->vmode |= FB_VMODE_CONUPDATE;
var->red.length = vmode->red.length;
var->red.offset = vmode->red.offset;
var->green.length = vmode->green.length;
var->green.offset = vmode->green.offset;
var->blue.length = vmode->blue.length;
var->blue.offset = vmode->blue.offset;
var->transp.length = vmode->transp.length;
var->transp.offset = vmode->transp.offset;
var->grayscale = vmode->grayscale;
}
static void ConvertToVideoMode(const struct fb_var_screeninfo *var,
struct VideoMode *vmode)
{
vmode->name = NULL;
vmode->xres = var->xres;
vmode->yres = var->yres;
vmode->vxres = var->xres_virtual;
vmode->vyres = var->yres_virtual;
vmode->depth = var->bits_per_pixel;
vmode->nonstd = var->nonstd;
vmode->accel_flags = var->accel_flags;
vmode->pixclock = var->pixclock;
vmode->left = var->left_margin;
vmode->right = var->right_margin;
vmode->upper = var->upper_margin;
vmode->lower = var->lower_margin;
vmode->hslen = var->hsync_len;
vmode->vslen = var->vsync_len;
vmode->hsync = var->sync & FB_SYNC_HOR_HIGH_ACT ? HIGH : LOW;
vmode->vsync = var->sync & FB_SYNC_VERT_HIGH_ACT ? HIGH : LOW;
vmode->csync = var->sync & FB_SYNC_COMP_HIGH_ACT ? HIGH : LOW;
vmode->gsync = var->sync & FB_SYNC_ON_GREEN ? TRUE : FALSE;
vmode->extsync = var->sync & FB_SYNC_EXT ? TRUE : FALSE;
vmode->bcast = var->sync & FB_SYNC_BROADCAST ? TRUE : FALSE;
vmode->grayscale = var->grayscale;
vmode->laced = FALSE;
vmode->dblscan = FALSE;
switch (var->vmode & FB_VMODE_MASK) {
case FB_VMODE_INTERLACED:
vmode->laced = TRUE;
break;
case FB_VMODE_DOUBLE:
vmode->dblscan = TRUE;
break;
}
vmode->red.length = var->red.length;
vmode->red.offset = var->red.offset;
vmode->green.length = var->green.length;
vmode->green.offset = var->green.offset;
vmode->blue.length = var->blue.length;
vmode->blue.offset = var->blue.offset;
vmode->transp.length = var->transp.length;
vmode->transp.offset = var->transp.offset;
FillScanRates(vmode);
}
static int atoboolean(const char *var)
{
int value = 0;
if (!strcasecmp(var, "false") || !strcasecmp(var, "low") ||
!strcasecmp(var, "no") || !strcasecmp(var, "off") ||
!strcmp(var, "0"))
value = 0;
else if (!strcasecmp(var, "true") || !strcasecmp(var, "high") ||
!strcasecmp(var, "yes") || !strcasecmp(var, "on") ||
!strcmp(var, "1"))
value = 1;
else
Die("Invalid value `%s'\n", var);
return value;
}
void AddVideoMode(const struct VideoMode *vmode)
{
struct VideoMode *vmode2;
if (FindVideoMode(vmode->name))
Die("%s:%d: Duplicate mode name `%s'\n", Opt_modedb, line,
vmode->name);
vmode2 = malloc(sizeof(struct VideoMode));
*vmode2 = *vmode;
if (!FillScanRates(vmode2))
Die("%s:%d: Bad video mode `%s'\n", Opt_modedb, line, vmode2->name);
vmode2->next = VideoModes;
VideoModes = vmode2;
}
/*
* Read the Video Mode Database
*/
static void ReadModeDB(void)
{
if (Opt_verbose)
printf("Reading mode database from file `%s'\n", Opt_modedb);
if (!(yyin = fopen(Opt_modedb, "r")))
Die("fopen %s: %s\n", Opt_modedb, strerror(errno));
yyparse();
fclose(yyin);
}
static void getColor(struct color *color, const char** opt)
{
char* ptr;
color->length = 0;
color->offset = 0;
ptr = (char*)(*opt);
if (!ptr)
return;
color->length = strtoul(ptr, &ptr, 0);
if (!ptr)
return;
if (*ptr == '/')
color->offset = strtoul(ptr+1, &ptr, 0);
if (ptr) {
while (*ptr && isspace(*ptr))
ptr++;
if (*ptr == ',') {
ptr++;
} else if (*ptr)
Die("Bad RGBA syntax, rL/rO,gL/gO,bL/bO,tL/tO or rL,gL,bL,tL\n");
}
*opt = ptr;
return;
}
void makeRGBA(struct VideoMode *vmode, const char* opt)
{
getColor(&vmode->red, &opt);
getColor(&vmode->green, &opt);
getColor(&vmode->blue, &opt);
getColor(&vmode->transp, &opt);
}
/*
* Find a Video Mode
*/
static struct VideoMode *FindVideoMode(const char *name)
{
struct VideoMode *vmode;
for (vmode = VideoModes; vmode; vmode = vmode->next)
if (!strcmp(name, vmode->name))
break;
return vmode;
}
/*
* Modify a Video Mode
*/
static void ModifyVideoMode(struct VideoMode *vmode)
{
u_int hstep = 8, vstep = 2;
if (Opt_xres)
vmode->xres = strtoul(Opt_xres, NULL, 0);
if (Opt_yres)
vmode->yres = strtoul(Opt_yres, NULL, 0);
if (Opt_vxres)
vmode->vxres = strtoul(Opt_vxres, NULL, 0);
if (Opt_vyres)
vmode->vyres = strtoul(Opt_vyres, NULL, 0);
if (Opt_depth)
vmode->depth = strtoul(Opt_depth, NULL, 0);
if (Opt_nonstd)
vmode->nonstd = strtoul(Opt_nonstd, NULL, 0);
if (Opt_accel)
vmode->accel_flags = atoboolean(Opt_accel) ? FB_ACCELF_TEXT : 0;
if (Opt_pixclock)
vmode->pixclock = strtoul(Opt_pixclock, NULL, 0);
if (Opt_left)
vmode->left = strtoul(Opt_left, NULL, 0);
if (Opt_right)
vmode->right = strtoul(Opt_right, NULL, 0);
if (Opt_upper)
vmode->upper = strtoul(Opt_upper, NULL, 0);
if (Opt_lower)
vmode->lower = strtoul(Opt_lower, NULL, 0);
if (Opt_hslen)
vmode->hslen = strtoul(Opt_hslen, NULL, 0);
if (Opt_vslen)
vmode->vslen = strtoul(Opt_vslen, NULL, 0);
if (Opt_hsync)
vmode->hsync = atoboolean(Opt_hsync);
if (Opt_vsync)
vmode->vsync = atoboolean(Opt_vsync);
if (Opt_csync)
vmode->csync = atoboolean(Opt_csync);
if (Opt_gsync)
vmode->gsync = atoboolean(Opt_gsync);
if (Opt_extsync)
vmode->extsync = atoboolean(Opt_extsync);
if (Opt_bcast)
vmode->bcast = atoboolean(Opt_bcast);
if (Opt_laced)
vmode->laced = atoboolean(Opt_laced);
if (Opt_double)
vmode->dblscan = atoboolean(Opt_double);
if (Opt_grayscale)
vmode->grayscale = atoboolean(Opt_grayscale);
if (Opt_step)
hstep = vstep = strtoul(Opt_step, NULL, 0);
if (Opt_matchyres)
vmode->vyres = vmode->yres;
if (Opt_move) {
if (!strcasecmp(Opt_move, "left")) {
if (hstep > vmode->left)
Die("The left margin cannot be negative\n");
vmode->left -= hstep;
vmode->right += hstep;
} else if (!strcasecmp(Opt_move, "right")) {
if (hstep > vmode->right)
Die("The right margin cannot be negative\n");
vmode->left += hstep;
vmode->right -= hstep;
} else if (!strcasecmp(Opt_move, "up")) {
if (vstep > vmode->upper)
Die("The upper margin cannot be negative\n");
vmode->upper -= vstep;
vmode->lower += vstep;
} else if (!strcasecmp(Opt_move, "down")) {
if (vstep > vmode->lower)
Die("The lower margin cannot be negative\n");
vmode->upper += vstep;
vmode->lower -= vstep;
} else
Die("Invalid direction `%s'\n", Opt_move);
}
if (Opt_rgba) {
makeRGBA(vmode, Opt_rgba);
}
if (!FillScanRates(vmode))
Die("Bad video mode\n");
}
/*
* Display the Video Mode Information
*/
static void DisplayVModeInfo(struct VideoMode *vmode)
{
u_int res, sstart, send, total;
puts("");
if (!Opt_xfree86) {
printf("mode \"%dx%d", vmode->xres, vmode->yres);
if (vmode->pixclock) {
printf("-%d\"\n", (int)(vmode->vrate+0.5));
printf(" # D: %5.3f MHz, H: %5.3f kHz, V: %5.3f Hz\n",
vmode->drate/1E6, vmode->hrate/1E3, vmode->vrate);
} else
puts("\"");
printf(" geometry %d %d %d %d %d\n", vmode->xres, vmode->yres,
vmode->vxres, vmode->vyres, vmode->depth);
printf(" timings %d %d %d %d %d %d %d\n", vmode->pixclock,
vmode->left, vmode->right, vmode->upper, vmode->lower,
vmode->hslen, vmode->vslen);
if (vmode->hsync)
puts(" hsync high");
if (vmode->vsync)
puts(" vsync high");
if (vmode->csync)
puts(" csync high");
if (vmode->gsync)
puts(" gsync true");
if (vmode->extsync)
puts(" extsync true");
if (vmode->bcast)
puts(" bcast true");
if (vmode->laced)
puts(" laced true");
if (vmode->dblscan)
puts(" double true");
if (vmode->nonstd)
printf(" nonstd %u\n", vmode->nonstd);
if (vmode->accel_flags)
puts(" accel true");
if (vmode->grayscale)
puts(" grayscale true");
printf(" rgba %u/%u,%u/%u,%u/%u,%u/%u\n",
vmode->red.length, vmode->red.offset, vmode->green.length,
vmode->green.offset, vmode->blue.length, vmode->blue.offset,
vmode->transp.length, vmode->transp.offset);
puts("endmode\n");
} else {
printf("Mode \"%dx%d\"\n", vmode->xres, vmode->yres);
if (vmode->pixclock) {
printf(" # D: %5.3f MHz, H: %5.3f kHz, V: %5.3f Hz\n",
vmode->drate/1E6, vmode->hrate/1E3, vmode->vrate);
printf(" DotClock %5.3f\n", vmode->drate/1E6+0.001);
} else
puts(" DotClock Unknown");
res = vmode->xres;
sstart = res+vmode->right;
send = sstart+vmode->hslen;
total = send+vmode->left;
printf(" HTimings %d %d %d %d\n", res, sstart, send, total);
res = vmode->yres;
sstart = res+vmode->lower;
send = sstart+vmode->vslen;
total = send+vmode->upper;
printf(" VTimings %d %d %d %d\n", res, sstart, send, total);
printf(" Flags ");
if (vmode->laced)
printf(" \"Interlace\"");
if (vmode->dblscan)
printf(" \"DoubleScan\"");
if (vmode->hsync)
printf(" \"+HSync\"");
else
printf(" \"-HSync\"");
if (vmode->vsync)
printf(" \"+VSync\"");
else
printf(" \"-VSync\"");
if (vmode->csync)
printf(" \"Composite\"");
if (vmode->extsync)
puts(" # Warning: XFree86 doesn't support extsync\n");
if (vmode->bcast)
printf(" \"bcast\"");
if (vmode->accel_flags)
puts(" # Warning: XFree86 doesn't support accel\n");
if (vmode->grayscale)
puts(" # Warning: XFree86 doesn't support grayscale\n");
puts("\nEndMode\n");
}
}
/*
* Display the Frame Buffer Device Information
*/
static void DisplayFBInfo(struct fb_fix_screeninfo *fix)
{
int i;
puts("Frame buffer device information:");
printf(" Name : %s\n", fix->id);
printf(" Address : %p\n", fix->smem_start);
printf(" Size : %d\n", fix->smem_len);
printf(" Type : ");
switch (fix->type) {
case FB_TYPE_PACKED_PIXELS:
puts("PACKED PIXELS");
break;
case FB_TYPE_PLANES:
puts("PLANES");
break;
case FB_TYPE_INTERLEAVED_PLANES:
printf("INTERLEAVED PLANES (%d bytes interleave)\n",
fix->type_aux);
break;
case FB_TYPE_TEXT:
for (i = 0; i < sizeof(Textmodes)/sizeof(*Textmodes); i++)
if (fix->type_aux == Textmodes[i].id)
break;
if (i < sizeof(Textmodes)/sizeof(*Textmodes))
puts(Textmodes[i].name);
else
printf("Unknown text (%d)\n", fix->type_aux);
break;
case FB_TYPE_VGA_PLANES:
{
struct textentry *t;
for (t = VGAModes; t->name; t++)
if (fix->type_aux == t->id)
break;
if (t->name)
puts(t->name);
else
printf("Unknown VGA mode (%d)\n", fix->type_aux);
}
break;
default:
printf("%d (UNKNOWN)\n", fix->type);
printf(" Type_aux : %d\n", fix->type_aux);
break;
}
printf(" Visual : ");
switch (fix->visual) {
case FB_VISUAL_MONO01:
puts("MONO01");
break;
case FB_VISUAL_MONO10:
puts("MONO10");
break;
case FB_VISUAL_TRUECOLOR:
puts("TRUECOLOR");
break;
case FB_VISUAL_PSEUDOCOLOR:
puts("PSEUDOCOLOR");
break;
case FB_VISUAL_DIRECTCOLOR:
puts("DIRECTCOLOR");
break;
case FB_VISUAL_STATIC_PSEUDOCOLOR:
puts("STATIC PSEUDOCOLOR");
break;
default:
printf("%d (UNKNOWN)\n", fix->visual);
break;
}
printf(" XPanStep : %d\n", fix->xpanstep);
printf(" YPanStep : %d\n", fix->ypanstep);
printf(" YWrapStep : %d\n", fix->ywrapstep);
printf(" LineLength : %d\n", fix->line_length);
if (fix->mmio_len) {
printf(" MMIO Address: %p\n", fix->mmio_start);
printf(" MMIO Size : %d\n", fix->mmio_len);
}
printf(" Accelerator : ");
for (i = 0; i < sizeof(Accelerators)/sizeof(*Accelerators); i++)
if (fix->accel == Accelerators[i].id)
break;
if (i < sizeof(Accelerators)/sizeof(*Accelerators))
puts(Accelerators[i].name);
else
printf("Unknown (%d)\n", fix->accel);
}
/*
* Calculate the Scan Rates for a Video Mode
*/
static int FillScanRates(struct VideoMode *vmode)
{
u_int htotal = vmode->left+vmode->xres+vmode->right+vmode->hslen;
u_int vtotal = vmode->upper+vmode->yres+vmode->lower+vmode->vslen;
if (vmode->dblscan)
vtotal <<= 2;
else if (!vmode->laced)
vtotal <<= 1;
if (!htotal || !vtotal)
return 0;
if (vmode->pixclock) {
vmode->drate = 1E12/vmode->pixclock;
vmode->hrate = vmode->drate/htotal;
vmode->vrate = vmode->hrate/vtotal*2;
} else {
vmode->drate = 0;
vmode->hrate = 0;
vmode->vrate = 0;
}
return 1;
}
/*
* Print the Usage Template and Exit
*/
static void Usage(void)
{
puts(VERSION);
Die("\nUsage: %s [options] [mode]\n\n"
"Valid options:\n"
" General options:\n"
" -h, --help : display this usage information\n"
" --test : don't change, just test whether the mode is "
"valid\n"
" -s, --show : display video mode settings\n"
" -i, --info : display all frame buffer information\n"
" -v, --verbose : verbose mode\n"
" -V, --version : print version information\n"
" -x, --xfree86 : XFree86 compatibility mode\n"
" -a, --all : change all virtual consoles on this device\n"
" Frame buffer special device nodes:\n"
" -fb <device> : processed frame buffer device\n"
" (default is " DEFAULT_FRAMEBUFFER ")\n"
" Video mode database:\n"
" -db <file> : video mode database file\n"
" (default is " DEFAULT_MODEDBFILE ")\n"
" Display geometry:\n"
" -xres <value> : horizontal resolution (in pixels)\n"
" -yres <value> : vertical resolution (in pixels)\n"
" -vxres <value> : virtual horizontal resolution (in pixels)\n"
" -vyres <value> : virtual vertical resolution (in pixels)\n"
" -depth <value> : display depth (in bits per pixel)\n"
" -nonstd <value> : select nonstandard video mode\n"
" -g, --geometry ... : set all geometry parameters at once\n"
" -match : set virtual vertical resolution by virtual resolution\n"
" Display timings:\n"
" -pixclock <value> : pixel clock (in picoseconds)\n"
" -left <value> : left margin (in pixels)\n"
" -right <value> : right margin (in pixels)\n"
" -upper <value> : upper margin (in pixel lines)\n"
" -lower <value> : lower margin (in pixel lines)\n"
" -hslen <value> : horizontal sync length (in pixels)\n"
" -vslen <value> : vertical sync length (in pixel lines)\n"
" -t, --timings ... : set all timing parameters at once\n"
" Display flags:\n"
" -accel <value> : hardware text acceleration enable (false or "
"true)\n"
" -hsync <value> : horizontal sync polarity (low or high)\n"
" -vsync <value> : vertical sync polarity (low or high)\n"
" -csync <value> : composite sync polarity (low or high)\n"
" -gsync <value> : synch on green (false or true)\n"
" -extsync <value> : external sync enable (false or true)\n"
" -bcast <value> : broadcast enable (false or true)\n"
" -laced <value> : interlace enable (false or true)\n"
" -double <value> : doublescan enable (false or true)\n"
" -rgba <r,g,b,a> : recommended length of color entries\n"
" -grayscale <value> : grayscale enable (false or true)\n"
" Display positioning:\n"
" -move <direction> : move the visible part (left, right, up or "
"down)\n"
" -step <value> : step increment (in pixels or pixel lines)\n"
" (default is 8 horizontal, 2 vertical)\n",
ProgramName);
}
/*
* Main Routine
*/
int main(int argc, char *argv[])
{
struct VideoMode *vmode;
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
int fh = -1, i;
ProgramName = argv[0];
/*
* Parse the Options
*/
while (--argc > 0) {
argv++;
if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help"))
Usage();
else if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose"))
Opt_verbose = 1;
else if (!strcmp(argv[0], "-V") || !strcmp(argv[0], "--version"))
Opt_version = 1;
else if (!strcmp(argv[0], "--test"))
Opt_test = 1;
else if (!strcmp(argv[0], "-s") || !strcmp(argv[0], "--show"))
Opt_show = 1;
else if (!strcmp(argv[0], "-i") || !strcmp(argv[0], "--info")) {
Opt_show = 1;
Opt_info = 1;
} else if (!strcmp(argv[0], "-x") || !strcmp(argv[0], "--xfree86"))
Opt_xfree86 = 1;
else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--all"))
Opt_all = 1;
else if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--geometry")) {
if (argc > 5) {
Opt_xres = argv[1];
Opt_yres = argv[2];
Opt_vxres = argv[3];
Opt_vyres = argv[4];
Opt_depth = argv[5];
Opt_change = 1;
argc -= 5;
argv += 5;
} else
Usage();
} else if (!strcmp(argv[0], "-t") || !strcmp(argv[0], "--timings")) {
if (argc > 7) {
Opt_pixclock = argv[1];
Opt_left = argv[2];
Opt_right = argv[3];
Opt_upper = argv[4];
Opt_lower = argv[5];
Opt_hslen = argv[6];
Opt_vslen = argv[7];
Opt_change = 1;
argc -= 7;
argv += 7;
} else
Usage();
} else if (!strcmp(argv[0], "-match")) {
Opt_matchyres = argv[0];
Opt_change = 1;
} else {
for (i = 0; Options[i].name; i++)
if (!strcmp(argv[0], Options[i].name))
break;
if (Options[i].name) {
if (argc-- > 1) {
*Options[i].value = argv[1];
Opt_change |= Options[i].change;
argv++;
} else
Usage();
} else if (!Opt_modename) {
Opt_modename = argv[0];
Opt_change = 1;
} else
Usage();
}
}
if (Opt_version || Opt_verbose)
puts(VERSION);
if (!Opt_fb)
Opt_fb = DEFAULT_FRAMEBUFFER;
/*
* Open the Frame Buffer Device
*/
fh = OpenFrameBuffer(Opt_fb);
/*
* Get the Video Mode
*/
if (Opt_modename) {
/*
* Read the Video Mode Database
*/
ReadModeDB();
if (!(vmode = FindVideoMode(Opt_modename)))
Die("Unknown video mode `%s'\n", Opt_modename);
Current = *vmode;
if (Opt_verbose)
printf("Using video mode `%s'\n", Opt_modename);
} else {
GetVarScreenInfo(fh, &var);
ConvertToVideoMode(&var, &Current);
if (Opt_verbose)
printf("Using current video mode from `%s'\n", Opt_fb);
}
if (Opt_change) {
/*
* Optionally Modify the Video Mode
*/
ModifyVideoMode(&Current);
/*
* Set the Video Mode
*/
ConvertFromVideoMode(&Current, &var);
if (Opt_verbose)
printf("Setting video mode to `%s'\n", Opt_fb);
SetVarScreenInfo(fh, &var);
ConvertToVideoMode(&var, &Current);
}
/*
* Display some Video Mode Information
*/
if (Opt_show || !Opt_change)
DisplayVModeInfo(&Current);
if (Opt_info) {
if (Opt_verbose)
puts("Getting further frame buffer information");
GetFixScreenInfo(fh, &fix);
DisplayFBInfo(&fix);
}
/*
* Close the Frame Buffer Device
*/
CloseFrameBuffer(fh);
exit(0);
}
|